Subject: AW: [xsl] Variables From: "Mengel Andre (FV/SLM) *" <Andre.Mengel@xxxxxxxxxxxx> Date: Thu, 17 May 2001 16:04:17 +0200 |
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: [xsl] 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 |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] Associating namespace pre, Jeni Tennison | Thread | AW: [xsl] Variables, Mengel Andre (FV/SLM |
Re: [xsl] XSL to generate XPaths, Jeni Tennison | Date | Re: [xsl] Variables, Oliver Becker |
Month |