Lists Home |
Date Index |
The suggested template fails if there is more than one occurrence of the
path the the elements, not because of the match, but because the path
produced leads to a nodeset containing more than one element.
Here is a document that the original stylesheet below will fail on. It will
produce /bookmarks/bookmark/item/findme, which does not uniquely identify
either of the abc or def findme elements in this document:
<?xml version="1.0" ?>
To fix this problem, you also need to introduce explicit , , etc at
each step. If the document is stable, then all you need is the position of
the elements, not the names.
An XSLT wizard such as Michael Kay probably has a better way to do this, but
try this version of the stylesheet, which instead of names uses a repeated
"/*[n]" construct to address an element uniquely, and which leaves off the
If you need to produce an XPath expression that finds the node even if the
rest of the document has been modified, then you can stick in an ID
addtibute using generate-id before the modifications. If you can't do that,
you need more help.
From: Mitch Amiano [mailto:email@example.com]
Sent: Friday, September 05, 2003 5:21 AM
To: Alejandro López
Subject: Re: [xml-dev] XSLT & XPATH absolute path
The ancestor-or-self:: axis pretty much gives you that information.
Assuming your node is an element named "findme", you can do something like
An xsl:choose can help you figure out which nodes are elements versus text
or attributes, in which case you can deal with the last path segment
separately by using the "ancestor::" axis instead of "ancestor-or-self::".
Alejandro López wrote:
> Hello everybody.
> Does anybody know if there is a way in xpath to know the absolute path of
> node in order to use with transformation functions?