Subject: RE: Parameters into variables
From: "Michael Kay" <mike@xxxxxxxxxxxx>
Date: Fri, 10 Oct 2008 11:32:37 +0100
|
It's always useful, rather than saying "it doesn't work", to say exactly how
it fails. Error message? Wrong results?
I can't see anything wrong with your code, it looks perfectly legal to me -
but I'm trying to debug it without the benefit of seeing its output.
Michael Kay
http://www.saxonica.com/
> -----Original Message-----
> From: Joe Barwell [mailto:jbar@xxxxxxxx]
> Sent: 10 October 2008 11:21
> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Subject: Parameters into variables
>
> Hello,
>
> XSLT 1.0 (e.g. Firefox 3.0, etc.)
>
> I have a template as follows:
>
> <xsl:template name="getCurrencySymbol">
> <xsl:param name="aCurrency" />
> <xsl:choose>
> <xsl:when test="$aCurrency='AUD'">A$</xsl:when>
> <xsl:when test="$aCurrency='EUR'">€</xsl:when>
> <xsl:when test="$aCurrency='GBP'">£</xsl:when>
> <xsl:when test="$aCurrency='NZD'">NZ$</xsl:when>
> <xsl:when test="$aCurrency='USD'">US$</xsl:when>
> <xsl:otherwise></xsl:otherwise>
> </xsl:choose>
> </xsl:template>
>
>
> At the top of my xsl stylesheet I want to put its value into a global
> variable:
>
> <xsl:variable name="theCurrencySymbol">
> <xsl:call-template name="getCurrencySymbol">
> <with-param name="aCurrency" select="'NZD'" />
> </xsl:call-template>
> </xsl:variable>
>
> But this does not work. Mangano (2003, p.120) shows that it
> will work if the template is called _without_ a parameter,
> and indeed I am able to do so successfully if I use a global
> variable, e.g. $baseCurrency, and change my getCurrencySymbol
> template so that it uses $baseCurrency (i.e.
> ignoring the $aCurrency parameter).
>
> The problem is that I would like to be able to re-use my
> getCurrencySymbol template elsewhere, but with a specified
> parameter in its call rather than a global.
>
> Is it really not possible to put the result of a template
> into a variable, if that template is being called using a
> parameter? I cannot think why such a minor distinction would
> be in the language.
>
> Cheers!
>
> Joe
|