[xsl] Restrict numbering to a sub tree

Subject: [xsl] Restrict numbering to a sub tree
From: Graeme Kidd <coolkidd3@xxxxxxxxxxx>
Date: Sat, 2 Apr 2011 05:36:12 +0100
Hi

I am using XSLT 2.0 and trying to number some elements
based on the current position within a sub tree as well as numbering which sub
tree it's in.

For example I could have the following mark-up:<root>
    <section>
        <figure />
        <section>
            <figure />
            <figure />
            <section>
                <figure />
            </section>
        </section>
        <section>
            <figure />
        </section>
    </section>
    <section>
        <figure />
    </section>
    <section>
        <figure />
        <figure />
    </section>
</root> 

Which I am wanting to convert to this:<root>
    <section>
        <figure id="1.1" />
        <section>
            <figure id="1.2" />
            <figure id="1.3" />
            <section>
                <figure id="1.4" />
            </section>
        </section>
        <section>
            <figure id="1.5" />
        </section>
    </section>
    <section>
        <figure id="2.1" />
    </section>
    <section>
        <figure id="3.1" />
        <figure id="3.2" />
    </section>
</root> 

As you can see the first number shows which "section" sub tree it is in while
the second number is used to show its current position within that sub tree
which could include further sub "sections".

 

I can easily use xsl:number to count every figure within
the root i.e:

<xsl:number level="any"
count="figure"/>

 

What I am finding difficult is limiting that count to
within the scope of the sub tree, conversely the same is said for
getting the count on the current sub tree it's in.
Some help on this would be greatly appreciated.

Thanks

Current Thread