[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: Use of variables in location paths
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
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|