Given the following simple input, I’d like to produce the simple output that follows that:




<a op=”x”>

                        <a op=”h”>

                                    <a op=”g”/>

                                    <a op=”q”/>






1. x

2. | h

3. | | g

4. | | q


The content to the right of the line number is easy with code like this:


            <xsl:template match="a">

                        <xsl:variable name="level" select="count(ancestor::row-source)"/>

                        <xsl:variable name="line-number" select="???"/>

                        <xsl:value-of select="$line-number"/>

                        <xsl:value-of select="string-join(for $i in 1 to $level return $HIERARCHY, '')"/>

                        <xsl:value-of select="@op"/>




My question is: Is there an [efficient] XSLT idiom that I can use to set the value of line-number to the right line number? My case seems like it should be simple, because the right line number is simply the position of the current node within the sequence ancestor:parent//a.


I don’t like the thought of having to use an intermediate tree and walk it by position, but I know how to do it if that’s the right way.


Cary Millsap
Hotsos Enterprises, Ltd.
Nullius in verba

Upcoming events:
- Performance Diagnosis 101: 1/4
- SQL Optimization 101: 11/8
Dallas, 12/13 Atlanta
- Hotsos Symposium 2005: March 6–10
- Visit for schedule details...