Martin Honnen wrote:
Jim Garrison wrote:
I know how to use the name() function to access the name of the
current node. How do I get the 'fully qualified' name, consisting
of the path from the root to the current node?
I.e.
<a>
<b>
<c>
</c>
</b>
</a>
When processing node c I need an xpath expression that returns
'a/b/c'. Is this available in XPath 1.0?
There is nothing like "the" fully qualified name in that way, of course
there are various XPath expressions selecting a single node but there is
nothing like "the XPath" to a node.
True, but I think what he wanted was the parental location ladder back to
the root element:
<?xml version="1.0" encoding="iso-8859-1"?>
<xsl:styleshe et xmlns:xsl="http ://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:output method="text"/>
<xsl:strip-space elements="*"/>
<xsl:template match="/">
<xsl:call-template name="parentage ">
<xsl:with-param name="element" select="//c"/>
</xsl:call-template>
</xsl:template>
<xsl:template name="parentage ">
<xsl:param name="trace"/>
<xsl:param name="element"/>
<xsl:choose>
<xsl:when test="count(/|$element)=1">
<xsl:value-of select="name($e lement)"/>
<xsl:text>/</xsl:text>
<xsl:value-of select="$trace"/>
</xsl:when>
<xsl:otherwis e>
<xsl:call-template name="parentage ">
<xsl:with-param name="element" select="$elemen t/parent::*"/>
<xsl:with-param name="trace">
<xsl:value-of select="name($e lement)"/>
<xsl:text>/</xsl:text>
<xsl:value-of select="$trace"/>
</xsl:with-param>
</xsl:call-template>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>
///Peter