[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

Re: [xsl] Relative XPATH between 2 nodes


Subject: Re: [xsl] Relative XPATH between 2 nodes
From: David Carlisle <davidc@xxxxxxxxx>
Date: Fri, 28 Jan 2005 14:49:24 GMT

> I'm looking for general algorithm,

What langauge do you need to implement this in?
In general it would need an XPath parser and writing an Xpath parser in
XSLT (or Xpath) would be entertaining. Also it depends on your
definitions and input. Is the input for the algorithm just the two
Xpaths or does it also include an input document.

If the input is just the Xpaths then clearly one algorithm  is to delete
"equivalent" steps from the start of each path, and then to  enough
../ to the second for each of the remaing steps in the first so

/a/b[2]/c/d
/a/b[2]/e/f

goes in the first stage to
c/d
e/f

and so finally returns a relative path of
../../e/f


However given 
id('x')
id('y')

you'd just have to return
id('y')

On the other hand, if you also input a particular document into teh
algorithm and ask for a relative Xpath that gets from one to teh other
_in that document_ you may well be able to return something else, eg
*[1]
if the structrure was
<foo id="x"><bar id="y"/>....

David

________________________________________________________________________
This e-mail has been scanned for all viruses by Star. The
service is powered by MessageLabs. For more information on a proactive
anti-virus service working around the clock, around the globe, visit:
http://www.star.net.uk
________________________________________________________________________


Current Thread
Keywords