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: "Richard Lewis" <richardlewis@xxxxxxxxxxxxxx>
Date: Fri, 20 May 2005 17:32:39 +0100
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