[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: Restrict numbering to a sub tree

Subject: Re: Restrict numbering to a sub tree
From: Brandon Ibach <brandon.ibach@xxxxxxxxxxxxxxxxxxx>
Date: Sat, 2 Apr 2011 01:10:53 -0400
Re:  Restrict numbering to a sub tree
All you really need is a pattern for what starts a sub tree.  In your
case, that's a "section" with no "section" ancestors.  Count those to
get the sub tree number and count *from* the last one of those for the
figure number:

    <xsl:number level="any" count="section[not(ancestor::section)]"/>
    <xsl:number level="any" format=".1"
from="section[not(ancestor::section)]"/>

This works for XSLT 1.0 or XSLT 2.0.

-Brandon :)


On Sat, Apr 2, 2011 at 12:36 AM, Graeme Kidd <coolkidd3@xxxxxxxxxxx> wrote:
>
>
>
>
> 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

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.