I think I got it… The content of the variable will be:

 

<xsl:number count="a" level="any" from="parent"/>

 

Yes?

 

Sorry for the interruption.

 

Cary Millsap
Hotsos Enterprises, Ltd.
http://www.hotsos.com
Nullius in verba

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

-----Original Message-----
From: saxon-help-admin@lists.sourceforge.net [mailto:saxon-help-admin@lists.sourceforge.net] On Behalf Of
Cary Millsap
Sent: Tuesday, November 23, 2004 4:15 PM
To: '
Saxon Help List'
Subject: [saxon] Idiom for line numbering

 

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

 

INPUT

<parent>

<a op=”x”>

                        <a op=”h”>

                                    <a op=”g”/>

                                    <a op=”q”/>

                        </a>

</a>

</parent>

 

OUTPUT

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"/>

                        <xsl:apply-templates/>

            </xsl:template>

 

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.
http://www.hotsos.com
Nullius in verba

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