Hi,
I try to select the value of a xsl:param. Therefore you have to provide its name. The name of the param is stored in a xsl:variable.
How do I write this?
Code:
Short sample:
<xsl:param name="foo:a" select="'Hallo'"/>
<xsl:variable name="paraname" select="'foo:a'" />
// this doesn't work
<xsl:value-of select="${$paraname}"/> World
Output should be:
Hallo world
The answer of course shouldn't be: <xsl:value-of select="$foo:a"/>, because that's not the problem. The sample above is the abstract of a more complicated situation.
Details and useable sample:
Code:
XML:
<?xml version="1.0" encoding="utf-8"?>
<title>This product was clicked <label id="clickrate"/> times and bought <label id="buyrate"/> times</title>
Code:
XSLT:
<?xml version="1.0" encoding="utf-8" ?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:foo="urn:foo"
>
<xsl:output method="html" encoding="utf-8" indent="yes" omit-xml-declaration="yes" />
<xsl:param name="foo:clickrate" select="'1000'"/>
<xsl:param name="foo:buyrate" select="'3'"/>
<xsl:template match="text()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="label">
<xsl:variable name="labelid" select="@id" />
<xsl:value-of select="concat('??value_of_param_foo:',$labelid,'??')"/>
</xsl:template>
</xsl:stylesheet>
Code:
Output:
This product was clicked ??value_of_param_foo:clickrate?? times and bought ??value_of_foo:buyrate?? times
The red marked parts in the output should be '1000' and '3'.
One solution for the label-template could be:
Code:
<xsl:template match="label">
<xsl:variable name="labelid" select="@id" />
<xsl:choose>
<xsl:when test="$labelid = 'clickrate'">
<xsl:value-of select="$foo:clickrate"/>
</xsl:when>
<xsl:when test="$labelid = 'buyrate'">
<xsl:value-of select="$foo:buyrate"/>
</xsl:when>
<xsl:otherwise></xsl:otherwise>
</xsl:choose>
</xsl:template>
But if you keep in mind that I've a lot of params to handle this xsl:choose statement becomes bigger and bigger.
I'd be grateful for any help. Thanks.
Best regards
polarbear