You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@xalan.apache.org by "Carwyn T. Edwards" <ca...@carwyn.com> on 2001/02/12 23:20:09 UTC

XPath Generator

I'd be very greatful to anyone who can help me with this one. I've been
looking around the web, ngs and in the Xalan 2 Api for a while now, but
can't seem to find a method that does something like:

public XPath generateXPath(Node rootNode, Node currentNode);

I.e. given the root and a sub-node returns the XPath to that node from
the root.

If there is not, then would it be as simple as using
node.getParentNode() until it == rootNode, storing the path on the way.
Obviously some house keeping would be needed for resolving indicies and
Node types ( /thing[1]/@myattrib ).

Carwyn


Re: XPath Generator

Posted by Gary L Peskin <ga...@firstech.com>.
"Carwyn T. Edwards" wrote:
> 
> I'd be very greatful to anyone who can help me with this one. I've been
> looking around the web, ngs and in the Xalan 2 Api for a while now, but
> can't seem to find a method that does something like:
> 
> public XPath generateXPath(Node rootNode, Node currentNode);
> 
> I.e. given the root and a sub-node returns the XPath to that node from
> the root.
> 
> If there is not, then would it be as simple as using
> node.getParentNode() until it == rootNode, storing the path on the way.
> Obviously some house keeping would be needed for resolving indicies and
> Node types ( /thing[1]/@myattrib ).

Carwyn --

I think this has been discussed before and I don't think that such a
thing currently exists in XalanJ2.  I think your description of the
implementation is pretty accurate but, as you said, you would need to
take position() indices into account.  There are probably some other
quirks as well.

If you can contribute the code back to the Xalan project, that would be
even better!

Gary