[xsl] Counting preceding-siblings with a different parent

Subject: [xsl] Counting preceding-siblings with a different parent
From: "Jim Neff" <jneff@xxxxxxxxxxxxxxx>
Date: Thu, 16 Dec 2004 10:15:50 -0500
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