Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


RE: [xsl] counting nodes before a certain node

From: "Michael Kay" <mike@--------.--->
To: <xsl-list@-----.------------.--->
Date: 11/30/2009 11:03:00 PM
Given XSLT 2.0, you can select two elements $a and $b, and then the number
of elements between these two is

count($b/preceding-sibling::*) - count($b/preceding-sibling::*) - 1

This is probably more efficient than

count(*[. >> $a and $b >> .])

but you can use that if it's more convenient.

(I'm assuming that by "between" you mean "between and on the same level".
That is, the number of elements between <a/> and <b/> in

<a/><node><child/></node><b/>

is one.)

Regards,

Michael Kay
http://www.saxonica.com/
http://twitter.com/michaelhkay 


> -----Original Message-----
> From: a kusa [mailto:akusa8@g...] 
> Sent: 30 November 2009 22:40
> To: xsl-list
> Subject: [xsl] counting nodes before a certain node
> 
> Hi
> 
> How do I count nodes up to a certain point in XSLT?
> 
> Example:
> 
> My xml file looks like this:
> 
> <books>
> <book>
> <title>First title</book>
> </book>
> <notes>The following books talk about history.</notes> 
> <notes>For further information please log on to </notes> 
> <notes>Thank you for choosing.. </notes> <book> 
> <title>Abraham Lincoln </title> </book>
> 
> <authors>
> sample data
> 
> </authors>
> <notes>Please call... </notes>
> <notes>Copyright Information </notes>
> <book>
> 
> sample data
> </book>
> </books>
> 
> In my XSLT file, I want to count all <notes> just before the 
> second <book> element but immediately after the first book 
> element or just after <authors>.
> 
> How do I count all the notes elements here?
> 
> --~------------------------------------------------------------------
> XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
> To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
> or e-mail: <mailto:xsl-list-unsubscribe@l...>
> --~--
> 


--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe@l...>
--~--



transparent
Print
Mail
Like It
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent