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: "Ross, Douglas" <DRoss@xxxxxxxxxx>
Date: Fri, 20 May 2005 13:06:49 -0400
Richard,

Did you just say RegEx is easy?! You are much smarter than you give
yourself credit for. :) Xpath started to make a lot more sense to me
when I implemented a simple XPath engine in ECMA Script for finding
nodes in HTML clients. I finally understand axis, determinates and the
current context node. Even with this understanding, I still find a lot
of this stuff is magic! By the way, my new moto is "XML is all!"

Douglas Ross
Developer, HTML UI Framework
Kronos
www.kronos.com

-----Original Message-----
From: Richard Lewis [mailto:richardlewis@xxxxxxxxxxxxxx]
Sent: Friday, May 20, 2005 12:33 PM
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject: Re: [xsl] relative path from one node to another (XSLT 2.0
solution)


On Fri, 20 May 2005 12:02:18 +0100, "David Carlisle" <davidc@xxxxxxxxx>
said:
>
>   //*[@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.
>
Oh, yes. I haven't got a DTD (yet). I was going to change the code I
posted to include the id() function so y'all didn't think I was stupid;
but then I forgot. So, evidently, I *am* stupid. Oh, well...

>   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']
>
Right. This works (just goes to show how little I really understand
XPath!)

> 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)
>
Hmm, yes that was a bit weird.
>
> 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.
>
Yes, thats right. I think I did say I was doing it like that; but not
because I thought that was a good way of doing it - just an easy way.
Yet again, my ignorance of XPath comes through: I never knew there were
intersect and except operators! (I wonder if XPath ignorance is
widespread or whether its just me? Is XPath difficult? I get on with C
all right and regular expressions are easy, but I often seem to get
stuck with XPath. Does anyone else feel like this?.....)

Cheers for your comments!

Richard

Current Thread