|
Subject: Re: [xsl] Retrieving Full XPATH expression From: "Robert Koberg" <rob@xxxxxxxxxx> Date: Fri, 10 Aug 2001 12:25:24 -0700 |
An easier way to do what I think you are trying to do is:
<xsl:template match="folder" mode="current-path-builder">
<xsl:apply-templates select="parent::folder"
mode="current-path-builder"/>
<xsl:value-of select="@name"/>
<xsl:text>/</xsl:text>
</xsl:template>
----- Original Message -----
From: "Tom Landon" <toml@xxxxxxxxxxxx>
To: <xsl-list@xxxxxxxxxxxxxxxxxxxxxx>
Sent: Friday, August 10, 2001 11:51 AM
Subject: RE: [xsl] Retrieving Full XPATH expression
> This is not exactly what you need, but it might be a good starting point:
>
> <!--
>
***************************************************************************
> Template
> path
>
> Description
> Converts a node to an XPath-like expression suitable for error
messages.
>
> Parameters
> node - Node to trace. Default value is ".".
>
****************************************************************************
> -->
> <xsl:template name="path">
> <xsl:param name="node" select="."/>
>
> <!-- Process ancestors first -->
> <xsl:if test="$node">
> <xsl:call-template name="path">
> <xsl:with-param name="node" select="$node/.."/>
> </xsl:call-template>
> </xsl:if>
>
> <!-- Process this node next -->
> <xsl:choose>
> <!-- No node. Either the original node was empty, or we have
> recursed
> past the root. -->
> <xsl:when test="not($node)"/>
>
> <!-- Root node -->
> <xsl:when test="not($node/..)">
> <xsl:text>/</xsl:text>
> </xsl:when>
>
> <!-- Attribute node (test if node is in set of parent's
> attributes) -->
> <xsl:when test="$node = $node/../@*">
> <!-- Do not output the 'name' predicate; the element has
output
> it -->
> <xsl:if test="name($node) != 'name'">
> <!-- Output the attribute's value as a predicate as an
> additional hint as to which element we are referencing -->
> <xsl:text/>[@<xsl:value-of
> select="name($node)"/>="<xsl:text/>
> <xsl:value-of select="$node"/>"]<xsl:text/>
> </xsl:if>
>
> <!-- Output the name of the element -->
> <xsl:text/>/@<xsl:value-of select="name($node)"/>
> </xsl:when>
>
> <!-- Some other node (with an optional 'name' attribute) -->
> <xsl:otherwise>
> <!-- Do not output a second / immediately after the root / -->
> <xsl:if test="$node/../.."> <!-- "if not a child of the
> root" -->
> <xsl:text>/</xsl:text>
> </xsl:if>
>
> <!-- Output the name of the element -->
> <xsl:value-of select="name($node)"/>
>
> <!-- Add a 'name' predicate if present as an additional hint
as
> to
> which element we are referencing -->
> <xsl:if test="$node/@name">
> <xsl:text/>[@name="<xsl:value-of
> select="$node/@name"/>"]<xsl:text/>
> </xsl:if>
> </xsl:otherwise>
> </xsl:choose>
> </xsl:template>
>
> -----Original Message-----
> From: owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> [mailto:owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx]On Behalf Of john smith
> Sent: Friday, August 10, 2001 11:17 AM
> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Subject: [xsl] Retrieving Full XPATH expression
>
>
> Given:
>
> <A>
> <B>
> <C>
> <D id="007">
> <E>val1</E>
> </D>
> <D id="008">
> <E>val2</E>
> </D>
> <C>
> </B>
> </A>
>
> How do I get the full Xpath for each node..For example, if the
> context node is <E> (with value "val1"), I want to get its full xpath
> as A/B/C/D[1]/E[1] and for the second occurrence of <E> (with value
"val2"),
> I want to get its full xpath as A/B/C/D[2]/E[2].
>
> Thanks a lot for the help.
>
> _________________________________________________________________
> Get your FREE download of MSN Explorer at http://explorer.msn.com/intl.asp
>
>
> XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
>
>
> XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
>
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
| Current Thread |
|---|
|
| <- Previous | Index | Next -> |
|---|---|---|
| RE: [xsl] Retrieving Full XPATH exp, Tom Landon | Thread | RE: [xsl] Retrieving Full XPATH exp, Oleg Tkachenko |
| Re: [xsl] Calculate mantissa and ex, David_Marston | Date | [xsl] Why doesn't <xsl:for-each sel, Hewko, Doug |
| Month |