[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

RE: Context node traversal inside predicates (was: Nod

Subject: RE: Context node traversal inside predicates (was: Nodes and Strings)
From: "Michael Kay" <mike@xxxxxxxxxxxx>
Date: Tue, 26 Jul 2005 14:35:46 +0100
RE:  Context node traversal inside predicates (was: Nod
> The 'context()' function would be similar to the 'current()' fuction.
> It would recall previous context nodes.
> 
> 'context(n)' would recall the n-th context node (as found 
> when propagating  
> upwards in the predicates of the expression)
> 
> e.g.:
> 'context(0)' is equal to '.'
> 'context(1)' is equal to the context node as constructed by the  
> immmediately outer predicate.
> ...
> 'context(-1)' would be equal to the context node as found in 
> the outermost  
> predicate.

Something like this was in an early draft of XPath 1.0, and was implemented
(IIRC) in WD-xsl, though I've rarely seen it used in practice.

I think the idea of manually addressing the stack of context variables is
very error-prone and counter-intuitive. The proper way to do this is to
declare a range variable. In XQuery you can do this using the "let" clause
of the FLWOR expression; XPath 2.0 has a poor man's version in the "for"
expression, which allows:

$SetA/Element[for $Z in . return $setB/Element[substring-after(.,'.')=$Z]]

In fact you might want to turn the whole thing into an XQuery-like join:

for $Z in $SetA/Element,
    $Y in $setB/Element
return
   if (substring-after($Y, '.') = $Z)
   then $Y else ()

Michael Kay
http://www.saxonica.com/

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.