|
Subject: Re: Change the value of global variables/params ?? From: David Carlisle <davidc@xxxxxxxxx> Date: Tue, 7 Dec 1999 15:40:24 GMT |
> Is it possible to assigne or change the value of a global variable or param
> within a template?
variables never change their value, parameters can be given new values
when the template is called (not inside the template)
> <xsl:variable name="variable.lang"/>
There's no point doing this as this variable will always have value
the empty string. Perhaps you wanted a top level xsl:param in which case
the value could be set when the stylesheet is called.
<xsl:template name="i18n">
<xsl:choose>
<xsl:when test="$variable.lang='en'">Abstract</xsl:when>
<xsl:when test="$variable.lang='fr'">Résumé</xsl:when>
...
</xsl:choose>
</xsl:template>
This doesn't work as the variable.lang is the variable declared at the
top level, which is always ''. If you want the template to take a
parameter called variable.lang, you must have a <xsl:param statement
at the start of _this_ template.
<xsl:template match="langset">
<!-- Set the value of language -->
<xsl:param name="variable.lang"><value-of select="@xml:lang"/></xsl:param>
...
<call-template name="i18n"/>
...
</xsl:template>
you see variable.lang need not be a parameter of your langset template
as this template does not depend on this parameter, but you could pass
on the value as a parameter to the cal-template
<xsl:template match="langset">
<call-template name="i18n">
<xsl:with-param name="variable.lang" select="@xml:lang"/>
</call-template>
...
</xsl:template>
However there is no real need to pass this information down as a
parameter, as all templates can get the information in the original
source tree.
so you could not bother with parameters and just have
<xsl:template name="i18n">
<xsl:variable name="variable.lang" select=
"ancestor-or-self::*/@xml:lang"/>
<xsl:choose>
<xsl:when test="$variable.lang='en'">Abstract</xsl:when>
<xsl:when test="$variable.lang='fr'">Résumé</xsl:when>
...
</xsl:choose>
</xsl:template>
David
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
| Current Thread |
|---|
|
| <- Previous | Index | Next -> |
|---|---|---|
| Change the value of global variable, Patrice Bonhomme | Thread | Re: Change the value of global vari, Paul Levin |
| new feature desired: return variabl, Paul Levin | Date | Re: new feature desired: return var, David Carlisle |
| Month |