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

RE: my node position within a certain context, effici

Subject: RE: my node position within a certain context, efficiently?
From: Syd Bauman <Syd_Bauman@xxxxxxxxx>
Date: Sat, 25 Oct 2008 15:07:31 -0400
RE:  my node position within a certain context
MG> It seems, a simple position() function would work here,

Thank you. While the actual code you posted doesn't work, a minor
modification thereof comes extremely close. Using position() as you
demonstrate in your reply
a) doesn't quite meet use-case, as this needs to be issued from the
   //box//thing template, and
b) results in 2 <box> containers in the output

The obvious slight modification to this suggestion comes a lot
closer: 
  <xsl:template match="/">
    <result>
      <xsl:apply-templates select="//box//thing"/>
    </result>
  </xsl:template>
  <xsl:template match="box//thing">
    <thing myCount="{position()}">
      <xsl:value-of select="."/>
    </thing>
  </xsl:template>

This results in all of the <thing> elements being counted
irrespective of their position within a <box>, though, whereas I had
asked to count their positions with respect to their ancestor <box>.
(Turns out for my real use-case, this isn't a very important
constraint, so in a pinch this solution would do, thank you.)


MK> I would use ... <xsl:number from="box"/>

Thank you! "I should have known to look at <xsl:number>, that bag of
holding of XSLT counting tricks" I thought to myself. But then I
tired it, and it didn't work, producing exactly what I didn't want
(count in relation to parent, not box). But, recalling there was a
lot more nuance to this element, I went and re-read the material on
<xsl:number> in your book. After adding
  level="any"
to my <xsl:number>, I get exactly the desired output. Yay!


Thanks again to both of you.

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.