Subject: [xsl] Re: Proper syntax for counting all prior nodes in XPath? (revised) From: Dimitre Novatchev <dnovatchev@xxxxxxxxx> Date: Tue, 12 Jun 2001 11:58:48 -0700 (PDT) |
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
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: using EXSLT {RE: [xsl] date cal, Xiaocun Xu | Thread | [xsl] xsl:variable, Jeff Fletcher |
using EXSLT {RE: [xsl] date calcula, B. Tommie Usdin | Date | Re: [xsl] generate unknow table, Thomas B. Passin |
Month |