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

Re: Counting preceding nodes

Subject: Re: Counting preceding nodes
From: Mukul Gandhi <mukul_gandhi@xxxxxxxxx>
Date: Fri, 24 Jun 2005 09:59:42 -0700 (PDT)
gandhi diagram
Hi Billie,
  Probably the following code might help ..

<xsl:template match="diagram">
    <xsl:attribute name="Number">
        <xsl:value-of select="count(preceding::node()
| ancestor::node())"/>

This is not tested. 

(I am relying on this technique based on a problem I
solved earlier.)


--- Billie <whynot77@xxxxxxxxxxxxx> wrote:

> I need help with a problem I'm having.  I need to
> count the number of nodes that come before the 
> given node, anywhere in the tree.
> So for example, say I have this tree:
> <book>
>     <chapter>
>         <para>
>             Blah blah blah
>             <diagram name="first"/>
>         </para>
>         <para>Blah blah blah</para>
>         <para>
>             <diagram name="second"/>
>             Blah blah blah
>         </para>
>         <diagram name="third"/>
>     </chapter>
>     <chapter>
>         <para>Blah blah blah</para>
>     </chapter>
>     <chapter>
>         <diagram name="fourth"/>
>         <para>Blah blah blah</para>
>     </chapter>
>     <chapter>
>         <para>
>             <quote>
>                 <diagram name="fifth"/>
>                 <diagram name="sixth"/>
>                 Blah blah blah
>             </quote>
>         </para>
>     </chapter>
> </book>
> I gave the diagrams the appropriate names so you
> could see what I was looking for, but basically, 
> I'm looking for a way to number the diagrams based
> on the absolute order in which they are placed.  
> I've tried all sorts of combinations but nothing
> seemed to work.  One logical structure I came up 
> with, that I couldn't figure out how to translate
> into XSL, was: "count the number of diagrams that 
> have an ancestor-or-self which is a
> preceding-sibling to an ancestor-or-self of the
> diagram in 
> question".  Is that possible to do?
> <xsl:template match="diagram">
>     <xsl:attribute name="Number">
>         <xsl:value-of select="???"/>
>     </xsl:attribute>		
> </xsl:template>
> Thanks for your help,
> Billie

Yahoo! Mail 
Stay connected, organized, and protected. Take the tour: 

Current Thread


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.
First Name
Last Name
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.