This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
Re: Use of variables in location paths
- To: Bob Kline <bkline at rksystems dot com>
- Subject: Re: [xsl] Use of variables in location paths
- From: Jeni Tennison <mail at jenitennison dot com>
- Date: Mon, 14 May 2001 17:20:52 +0100
- CC: XSL/T Mailing List <xsl-list at lists dot mulberrytech dot com>
- Organization: Jeni Tennison Consulting Ltd
- References: <Pine.LNX.4.10.10105141122440.8226-100000@rksystems.com>
- Reply-To: xsl-list at lists dot mulberrytech dot com
Hi Bob,
> In response to an ancient posting from Jon Smirl (later reproduced
> in the FAQ document), Ken Holman once wrote:
>
> "If the variable isn't a node set, then it cannot be used directly
> as a location step in a location path."
>
> I can see from the behavior of every XSL/T process that I have tried
> this this is clearly true. My question is, how would I have been
> able to come to this conclusion solely from reading the language in
> the W3C recommendations? Can anyone point me to the specific
> passages which make it clear that node set variables can be used in
> a location path but string variables cannot?
The relevant spec is the XPath Recommendation
(http://www.w3.org/TR/xpath). Actually Ken's terminology was a little
misleading if you're going spec-trawling. What you're really talking
about here is a 'path expression', or PathExpr
(http://www.w3.org/TR/xpath#NT-PathExpr). Have a look at Section 3.3
Node-Sets (http://www.w3.org/TR/xpath#node-sets), and you'll see it
says:
"The / and // operators compose an expression and a relative
location path. It is an error if the expression does not evaluate to
a node-set. The / operator does composition in the same way as when
/ is used in a location path. As in location paths, // is short for
/descendant-or-self::node()/."
More technically, if you look at the BNF for PathExpr, you'll see:
PathExpr ::= LocationPath
| FilterExpr
| FilterExpr '/' RelativeLocationPath
| FilterExpr '//' RelativeLocationPath
So, the path expressions can *start with* a filter expression, which,
if you follow through the non-terminals, you'll see can be a primary
expression, which can be a variable reference (or various other
things).
>From the text above the BNF, the (filter) expression has to result in
a node set. So you can't use a variable reference that evaluates to a
string at the beginning of a path expression.
When you use a variable reference at the beginning of a path
expression, technically it isn't a step, it's a filter expression.
Needless to say, you can't use a variable reference of any kind as a
step within a relative location path.
I hope that helps,
Jeni
---
Jeni Tennison
http://www.jenitennison.com/
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list