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

Re: Variables

Subject: Re: Variables
From: Oliver Becker <obecker@xxxxxxxxxxxxxxxxxxxxxxx>
Date: Thu, 17 May 2001 16:11:27 +0200 (MET DST)
variable becker
> Could someone explain me the following example of the W3C specification
> 
> <xsl:variable name="n">2</xsl:variable>
> ...
> <xsl:value-of select="item[$n]"/>
> 
> This will output the value of the first item element, because the variable n
> will be bound to a result tree fragment, not a number.
> (See chapter 11.2)
> 
> What is the reason for outputing the value of only the first item element ?

You are referring to http://www.w3.org/TR/xslt#variable-values

Ok, step by step:
item[$n] contains a predicate: [$n], whose expression is $n, which
in turn is a result tree fragment.

Looking at http://www.w3.org/TR/xpath#predicates
you'll find the following:
"... If the result [of evaluating the PredicateExpr (my annotation)] is a
number, the result will be converted to true if the number is equal to the 
context position and will be converted to false otherwise; if the result is 
not a number, then the result will be converted as if by a call to the 
boolean function."

$n isn't a number (it's a rtf), so it is converted to a boolean, i.e.
to true (the rtf isn't empty).

item[true()] then selects all the item nodes, it is a node-set.

xsl:value-of select="item[$n]" outputs the string value of the
select expression: http://www.w3.org/TR/xslt#value-of
It does this by using the string function.

The string function with a node-set as argument returns the string value
of the first node in document order: http://www.w3.org/TR/xpath#function-string

In the end what you get is the value of first item element.

Questions?

I think in addition the work-arounds given in the XSLT spec, it's also
possible to write: item[number($n)]

Cheers,
Oliver


/-------------------------------------------------------------------\
|  ob|do        Dipl.Inf. Oliver Becker                             |
|  --+--        E-Mail: obecker@xxxxxxxxxxxxxxxxxxxxxxx             |
|  op|qo        WWW:    http://www.informatik.hu-berlin.de/~obecker |
\-------------------------------------------------------------------/


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


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.