Project

Profile

Help

getting the xpath expression of a node

Added by Anonymous over 16 years ago

Legacy ID: #4536274 Legacy Poster: Martin Roberts (robertmm)

Hi, Is there a quick way to get the xpath of a node in xslt 2.0? Martin


Replies (1)

RE: getting the xpath expression of a node - Added by Anonymous over 16 years ago

Legacy ID: #4536304 Legacy Poster: Michael Kay (mhkay)

There's no such thing as "the XPath of a node": there are an infinite number of paths that will identify a given node. People usually want something like /a[1]/b[3]/c[5] which is easy enough to do with a template like <xsl:template match="" mode="path"> <xsl:apply-templates select=".." mode="path"/> <xsl:value-of select="concat('/', name())"/> <xsl:number format="[1]"/> </xsl:template> <xsl:template match="/" mode="path"/> But note that this path will contain namespace prefixes and there's nothing in the output to tell you what they are bound to, so the path can't actually be used to retrieve the node. If you want a path for that purpose then it's better to generate something like /[1]/[3]/[5], or even //*[831].

    (1-1/1)

    Please register to reply