Re: [xsl] xsl:value-of

Subject: Re: [xsl] xsl:value-of
From: Jeni Tennison <jeni@xxxxxxxxxxxxxxxx>
Date: Mon, 1 Jul 2002 14:05:08 +0100
Hi Cenk,

> Here is the part of XSL:
>
> <xsl:for-each select="b[@at=$something]">  
>   <xsl:value-of select="../b"/>
> </xsl:for-each>

When you use xsl:for-each, the processor cycles through the nodes that
you select (in this case the b elements whose 'at' attribute equals
the value of the variable $something). Within the xsl:for-each, the
particular node that's being processed becomes the current node, and
all the paths within the loop are resolved relative to this current
node.

Now, in your case, on each iteration, a b element is the current node.
You use the path "../b" within the xsl:value-of element. This tells
the processor to go up to the parent of the current b element (to the
a element) and then down again to get all the b element children of
that element. This always gives you a node set containing all the b
elements. xsl:value-of gives you the value of whatever you select; if
you select a node set, like you're doing here, it gives you the value
of the first node in that node set. So each time you get the value of
the first b element within the a element.

I think that what you want to do is get the value of the current b
element, the one you're looking at within the loop. To do that, just
use the XPath ".":

  <xsl:for-each select="b[@at = $something]">
    <xsl:value-of select="." />
  </xsl:for-each>

(BTW, if you want to copy it rather than get its value, just use
xsl:copy-of instead of xsl:value-of.)
  
Cheers,

Jeni

---
Jeni Tennison
http://www.jenitennison.com/


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


Current Thread