Re: [xsl] XPath context evaluation

Subject: Re: [xsl] XPath context evaluation
From: Victor Toni <xsl-list@xxxxxxxxx>
Date: Fri, 12 May 2006 22:12:07 +0200
David Carlisle wrote:
I apologize for hijacking the XSL list for XPath questions,

xpath is on-topic here.

I have written some XSL-like application ...
however I am not able to
use the current context (one of the <id> elements in the <idList>) to
evaluate an XPath expression as "//info[id = .]"

In pure Xpath 1 you can't do this. XSLT has three solutions though so you just need to implement one of those in your language

1) an additional xpath function, current()

"//info[id = current()]"


2) The ability to bind XPath variables in the host language

<xsl:variable name="here" select="."/>
   .... select="//info[id = $here]"

3) Implement (at least parts of) XPath2 to allow variable binding within

select="for $here in . return //info[id = $here]"

Thanks for your help.

Since I am using Jaxen as my XPath engine I am not able to implement a "current()" function due to Jaxen's design regarding context (no access to caller's or initial context).
However I've been able to solve this problem by using some trivially to implement XPath 2.0 functions:

"subsequence(//info,index-of(//info/id, .), 1)"

Since I am not using square brackets the context doesn't change but it's not what I would call elegant ;-)


Current Thread