This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Proper syntax for counting all prior nodes in XPath? (revised)


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]