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

AW: Variables

Subject: AW: Variables
From: "Mengel Andre (FV/SLM) *" <Andre.Mengel@xxxxxxxxxxxx>
Date: Thu, 17 May 2001 16:04:17 +0200
AW:  Variables
Hi Jeni,

thanx for your detailed description.

Best regards,

André

> -----Ursprüngliche Nachricht-----
> Von: Jeni Tennison [mailto:mail@xxxxxxxxxxxxxxxx]
> Gesendet: Donnerstag, 17. Mai 2001 15:43
> An: Mengel Andre (FV/SLM) *
> Cc: 'XSL-List@xxxxxxxxxxxxxxxxxxxxxx'
> Betreff: Re:  Variables
> 
> 
> Hi Mengel,
> 
> > 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 ?
> 
> The definition of xsl:value-of indicates that it evaluates the
> expression in its select attribute, and converts that to a string in
> the same way as the string() function (see Section 7.6.1 of the XSLT
> Recommendation).
> 
> When you convert a node set to a string with the string function, you
> always get the value of the *first* node in that node set (see Section
> 4.2 of the XPath Recommendation).
> 
> The XPath 'item[$n]' gets a node set of item elements that are
> children of the current node. The item elements that are chosen depend
> on the data type of the predicate. If the predicate were a number
> (e.g. item[2]) then it would get the item element that had that
> position amongst its sibling item elements (i.e. the second item
> element).  Otherwise, the expression is converted to boolean in the
> same way as the boolean() function (see Section 2.4 of the XPath
> Recommendation).
> 
> In this case, and the point of the example, the variable $n is set to
> a result tree fragment. Evaluating the variable gives a result tree
> fragment, not a number, so it's converted to a boolean.  Converting
> a result tree fragment to a boolean always results in true() because a
> result tree fragment is treated, in this context, like a node set with
> a single root node (which has children as defined by the content of
> the variable).
> 
> As the predicate always evaluates to true, the node set returned by
> 'item[$n]' holds all the item children of the current node.  When this
> node set is evaluated as a string, then you get the string value of
> the first of the item elements.
> 
> I hope that helps,
> 
> Jeni
> 
> ---
> Jeni Tennison
> http://www.jenitennison.com/
> 
> 

 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.