cocoon-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Andrew Stevens" <at...@hotmail.com>
Subject RE: How to asign a value to a variable??
Date Wed, 18 Jan 2006 18:38:07 GMT
>From: "Christian Barth" <cocoon@barth-zone.de>
>Date: Wed, 18 Jan 2006 19:20:37 +0100
>
>Hi!
>
>I want to define a global variable with no value.
>
>Then I want to asign a value to the variable in a choose-when-select.
>
>I think of something like this (but this one doesn't work):
>
><xsl:variable name="element" />
>     <xsl:for-each select="*">
>         <xsl:choose>
>             <xsl:when test="local-name() = 'rettungswege'">
>                 <xsl:variable name="element" select="rettungswege/rw" />
>             </xsl:when>
>             <xsl:when test="local-name() = 'trennwaende'">
>                 <xsl:variable name="element" 
>select="trennwaende/trennwand"
>/>
>             </xsl:when>
>         </xsl:choose>
>     </xsl:for-each>
><xsl:for-each select="$element">
>     ...do something...
></xsl:for-each>
>
>Is this possible?

No, because that's not how variables work in XSL.  Once they're assigned 
they're visible at that level and below, and you can't change them.  You 
have to use something structured more like

<p>Try visiting<ul>
<xsl:for-each select="tutorial">
<xsl:variable name="foo">
<xsl:choose>
<xsl:when test="@id = '1'>
http://www.topxml.com/xsl/tutorials/intro/default.asp
</xsl:when>
<xsl:when test="@id = '2'>
http://en.wikipedia.org/wiki/XSLT
</xsl:when>
<xsl:otherwise>
http://www.jenitennison.com/xslt/
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<li><xsl:value-of select="$foo"/></li>
</xsl:for-each>
</ul></p>

This isn't really a Cocoon issue, though, and there are plenty of dedicated 
XSL sites and mailing lists...


Andrew.



---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org


Mime
View raw message