This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
Proper syntax for counting all prior nodes in XPath? (revised)
- To: "'XSL-List at lists dot mulberrytech dot com'" <XSL-List at lists dot mulberrytech dot com>
- Subject: [xsl] Proper syntax for counting all prior nodes in XPath? (revised)
- From: Jason Morris <jason dot morris at directwest dot com>
- Date: Tue, 12 Jun 2001 11:50:35 -0600
- Reply-To: xsl-list at lists dot mulberrytech dot com
Thanks for the help on my original problem. I would now like to revise it
slightly, which makes it more complicated (for a beginner like me, anyway).
With an XML document like this:
<DOC>
<CHAPTER>
<SECTION>
<PAGE>
<LINE>Test</LINE>
<LINE>Test 2</LINE>
</PAGE>
</SECTION>
<SECTION>
<PAGE>
<LINE>Test 3</LINE>
</PAGE>
</SECTION>
</CHAPTER>
<CHAPTER>
<SECTION>
<PAGE>
<LINE>Test 4</LINE>
<LINE>Test 5</LINE>
</PAGE>
</SECTION>
<SECTION>
<PAGE>
<LINE>Test 6</LINE>
</PAGE>
</SECTION>
</CHAPTER>
</DOC>
How can my XSL count all the preceding nodes within the same chapter? For
example, when my template is processing the <LINE>Test 6</LINE>, I want to
count all nodes before it within the current <CHAPTER> tag. Therefore, it
would be 2 <LINE>s, 2 <PAGE>s, 2 <SECTION>s, and 1 <CHAPTER>. Does this
make sense?
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.
But this counts everything, not just within the current <CHAPTER> node.
What is the most efficient way of modifying it to count only the prior nodes
in the current <CHAPTER>?
Thanks
Jason
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list