|
[XML-DEV Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: Generating XPath expressions
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.
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|
|||||||||

Cart








