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

Re: How to resolve the absolute location of a node

Subject: Re: How to resolve the absolute location of a node
From: "Clark C. Evans" <clark.evans@xxxxxxxxxxxxxxxxxxxx>
Date: Sun, 17 Oct 1999 15:38:35 -0400 (EDT)
clark evans index
On Sun, 17 Oct 1999, Jarno Elovirta wrote:
> I'm trying to write a template that would return the absolute location path
> of the node i'm processing. e.g. with processing the c elements of
> 
> >      <a><b x="y"><c/></b><b x="z" p="q"><c/></b></a>
> 
> the templete would return
> 
> /a/b[1]/c[1] and /a/b[2]/c[1]
> 

How about this?


<xsl:template match="*">
  <xsl:call-template name="resolver" />
  <xsl:apply-templates/>
</xsl:template>

<xsl:template name="resolver" >
  <xsl:for-each select="ancestor-or-self::*">
    <xsl:variable name="currpos" select="generate-id(.)" />
    <xsl:value-of select="concat('/',name())"/>
      <xsl:for-each select="../*" >
        <xsl:if test="generate-id(.)=$currpos">
          <xsl:text>[</xsl:text>
          <xsl:value-of select="position()"/>
          <xsl:text>]</xsl:text>
        </xsl:if>
      </xsl:for-each> 
  </xsl:for-each>
</xsl:template>



 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


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.