[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Proper syntax for counting all prior nodes in XPath? (

Subject: Proper syntax for counting all prior nodes in XPath? (revised)
From: Jason Morris <jason.morris@xxxxxxxxxxxxxx>
Date: Tue, 12 Jun 2001 11:50:35 -0600
proper syntax
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


Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.