xsl-list
[Top] [All Lists]

Counting preceding-siblings with a different parent

2004-12-16 08:15:50
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


--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--