|
[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: Proper syntax for counting all prior nodes in XPat
Jason Morris wrote: > Originally I wanted all prior nodes. Now I want to restrict my prior nodes > to within a specific ancestor. > > I was originally using > <xsl:variable > name="num_rows" > > select="count(preceding::LINE)+count(preceding::PAGE)+count(preceding::SECTI > ON)+count(preceding::CHAPTER)"/> > as recommended by another list member. Whoever recommended this was wrong! What you mean by "prior" nodes includes all nodes before the current in document order. Because the "preceding" and "ancestor" axes are non-overlapping, using only the "preceding" axes in the above expression will fail to count the ancestors of the current node. A small example: xml source (simplified): ----------------------- <CHAPTER> <SECTION> <PAGE> <LINE>Test 4</LINE> <LINE>Test 5</LINE> </PAGE> </SECTION> <SECTION> <PAGE> <LINE>Test 6</LINE> </PAGE> </SECTION> </CHAPTER> Suppose your current node is <LINE>Test 6</LINE>. Then count(//LINE[contains(.,'6')]/preceding::PAGE) is 1 and not 2, as you said you expected. The correct expression counting ***all*** prior nodes must count all "ancestor" nodes in addition to the "preceding" nodes: count(//LINE[contains(.,'6')]/preceding::PAGE | //LINE[contains(.,'6')]/ancestor::PAGE ) is 2 Hope this helped. Cheers, Dimitre Novatchev. __________________________________________________ Do You Yahoo!? Get personalized email addresses from Yahoo! Mail - only $35 a year! http://personal.mail.yahoo.com/ XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|

Cart








