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

Counting preceding-siblings with a different parent

Subject: Counting preceding-siblings with a different parent
From: "Jim Neff" <jneff@xxxxxxxxxxxxxxx>
Date: Thu, 16 Dec 2004 10:15:50 -0500
count preceding
Greetings,

I'm having some trouble understanding how to count preceding-siblings that
have different parents.

Here is a sample of my source XML document:

<claim_file>
	<provider>
		<provider_id>1234</provider_id>
		<claim>
			<claim_id>121</claim_id>
			<service_date>2003-08-11</service_date>
			<claim_line>
				<billed_amount>300.45</billed_amount>
			</claim_line>
			<claim_line>
				<billed_amount>22</billed_amount>
			</claim_line>
			<claim_line>
				<billed_amount>500</billed_amount>
			</claim_line>
		</claim>
	</provider>
	<provider>
		<provider_id>5533</provider_id>
		<claim>
			<claim_id>201</claim_id>
			<service_date>2004-10-01</service_date>
			<claim_line>
				<billed_amount>10</billed_amount>
			</claim_line>
			<claim_line>
				<billed_amount>43</billed_amount>
			</claim_line>
		</claim>
	</provider>
</claim_file>

Here is the xsl file:

	<xsl:template match="claim_file">
		
		<xsl:apply-templates select="provider/claim/claim_line"/>
		
	</xsl:template>
	
	<xsl:template match="claim_line">
	
		<xsl:value-of select="count(preceding-sibling::*)"/>
		
	</xsl:template>


This will give me something like:

2
3
4
2
3

What I want is:

1
2
3
4
5


I realize what is happening but I don't know how to fix it.  I am getting
the count of only those siblings with the same parent, rather than the
ordinal position of the current claim_line node relative to the root.

My natural tendency would be to build a temporary tree of only claim_line
nodes with only the data that I need, but I want to find a way (if possible)
to do this without having to re-structure my data (again).

In english: what I want to do is find the position (relative to the root
node) of the current claim_line node.

My current statement:  count($p1/preceding-sibling::*)  obviously does not
work.


Thanks in advance,
Jim Neff

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.