[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 15:42:24 GMT

  That's not necessary the case.

'tis so:-)

 (except for the special cases of replacing self::*[1] and
ancestor::*[1] by . and ..)

  Here is the example
  Node A:
  Node B:
  The short cut doesn't follow xxx::*[n]

I wrote

> then I think in general for two element nodes, 

Just to save me writing out the full version, which I will now do:-)

neither of those are element nodes. if you want to include text and
comment nodes then just replace * by node() (and use a different number
for n)

If you need to include namespace and attribute nodes as a possibility for
the target then you  can use the above format to find the parent and add
oe more step namespace::abc or attribute::abc.

So you never need more than two steps.

So the general format for the shortest relative Xpath between two nodes
in the same document is is one of



 xxx is one of a
  ancestor self preceding following descendant
 yyy is one of
   namespace attribute
 zzz is a QName (name of an attribute or namespace node)
and n is a positive integer

You could get a shorter path than that eg if there is only one foo child
you could use foo rather than descendant::foo[1] but you can not use
less steps I believe.


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:

Current Thread