Re: [xsl] relative path from one node to another (XSLT 2.0 solution)

Subject: Re: [xsl] relative path from one node to another (XSLT 2.0 solution)
From: David Carlisle <davidc@xxxxxxxxx>
Date: Fri, 20 May 2005 12:02:18 +0100
> First thing I did was to give the document (root) node an id attribute

terminological quibble: the document note (Xpath2 terminology) or root
not (XPath 1 terminoligy) is / the notional top of the document, not the
top level element (so it doesn't take an attribute).


  //*[@id=$from-id]

That's a bit expensive (and you do it twice) if your file has a dtd and
these are ID attributes you could use id($from-id) or if not you could
set up an equivalent key and do the same thing.

  id($from-id)/ancestor::*[(name()='section'   or name()='document')

You could write that as

   id($from-id)/ancestor::*[self::section or self::document][@display='page']

or even, since this is xpath2

 id($from-id)/(ancestor::*section|ancestor::document)[@display='page']

although I would guess this causes the system to do more node
re-ordering (or perhaps it just get re-written back to the self:: form
anyway)


You are generating long paths going up to the top and down again
however once you have the two sets of attribute nodes then you could use
the xpath2 except operator to  prune the nodes that are in both sets s
so you only need to go up as far as the first ancestor that is shared
between from-id and to-id.

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