Mittwoch, 29. April 2009

Howto overwrite variables in XSL

XSL is sometimes pretty nasty. Lots of commonly programming stuff isn't available, p.e. loops. Even the simplest operation - overwriting values of variables - is pretty tricky, and cannot actually been done in the way we would like to. And apparently its not even possible to globally overwrite the value.
The only way to set the value of a xsl:variable is to do it at the initialization, in the body of it.

<xsl:variable name="myvar">
<xsl:choose>
<xsl:when test="condition'">
<xsl:value-of select="$value"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$other_value"/>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>



So if you start your initialization like this

<xsl:variable name="myvar4" select="lower-case($name)"/>


you cannot change its level anmore (globally).

Keine Kommentare:

Kommentar veröffentlichen