Hi,
In the xml structure below, imagine:
- all nodes have name (not necessarily unique) and id (unique)
attributes
- you are in the context of node[(_at_)id='a3'] and you want to build a path
from the name attribute to node[(_at_)id='b3'] that would result in the
shortest path, which would be:
../../../bar/baz/bat
- and in another case you are in the context of node[(_at_)id='c3'] and you
want the shortest path to node[(_at_)id='b3'], which would be:
../../baz/bat
- and in another case you are in the context of node[(_at_)id='b4'] and you
want the shortest path to node[(_at_)id='b3'], which would be:
bat
What is the most efficient to find those paths? (this is to create page
relative links, rather than root relative, for html pages)
In the past I have just recursed up the ancestry of the calling node to
the root element and for each of those added a '../'. Then used a key to
find the target node and recurse up from that target to root prepending
the name attribute. Now, using XSL and XPath version 2, I am hoping
there is a clean, efficient way to find the shortest possible path
rather than going all the way to the root when it is not necessary.
<node name="foo" id="x">
<node name="bar" id="b1">
<node>
<node/>
<node/>
</node>
<node name="baz" id="b2">
<node name="bat" id="b3"/>
<node name="bat" id="b4"/>
</node>
<node>
<node name="saz" id="c2">
<node name="sat" id="c3"/>
</node>
</node>
</node>
<node name="gar" id="a1">
<node name="gaz" id="a2">
<node name="gat" id="a3"/>
<node/>
</node>
<node>
<node/>
</node>
<node>
<node/>
</node>
</node>
</node>
--~------------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--