OASIS Mailing List ArchivesView the OASIS mailing list archive below
or browse/search using MarkMail.

 


Help: OASIS Mailing Lists Help | MarkMail Help

 


 

   Re: Generating XPath expressions

[ Lists Home | Date Index | Thread Index ]
  • From: Francis Norton <francis@redrice.com>
  • Date: Tue, 12 Dec 2000 14:17:23 +0000



Sanjay Khattar wrote:
> > >
> > Perhaps what you want is:
> >
> > given a context (DOM) node and a target (DOM) node,
> > construct an XPath
> > which will select the target from the context.
> 
> Exactly. That's what I want.
> 

Try this ...

<xsl:template name="mypath">
  <xsl:for-each select="(ancestor-or-self::*|@*)">
    <xsl:choose>
      <xsl:when test=". = /"/>
      <xsl:otherwise>/<xsl:value-of select=
	"concat(name(.), '[', count(preceding-sibling::*[name(current()) =
name(.)]) + 1, ']')"
					/>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:for-each>
</xsl:template>

... for an elements-only solution in XSLT, that generates 
"/a[1]/b[3]/c[1]" style xpath for any given context node.

Francis.




 

News | XML in Industry | Calendar | XML Registry
Marketplace | Resources | MyXML.org | Sponsors | Privacy Statement

Copyright 2001 XML.org. This site is hosted by OASIS