5 users online. Create an account or sign in to join them.Users
Parameter / Variable question
This is an open discussion with 4 replies, filed under XSLT.
Search
try this:
<xsl:template name="checksite">
<xsl:variable name="site">
<xsl:choose>
<xsl:when test="$root = 'http//www.abc.com'">
<xsl:value-of select="'abc'">
</xsl:when>
<xsl:when test="$root = 'http//www.xyz.com'">
<xsl:value-of select="'xyz'" />
</xsl:when>
</xsl:choose>
</xsl:variable>
My variable is: <xsl:value-of select="$site" />
</xsl:template>
And remeber that variable in xsl is not real variable once you set it, you can’t change it. It works like a constant.
Thanks! However, I already had achieved the same result in the meanwhile with a shorter approach like this:
<xsl:variable name="site" select="substring-before(substring-after($root, 'http://'), '.')" />
While I am typing it, I see my shorter approach will not work because it will give problems when vistors type ‘www.website.com’ or ‘website.com’ in their address bar :S
Looks like I’m going to use the slightly longer approach after all ;)
Create an account or sign in to comment.
I try to set a parameter or variable, but with no success… Why doesn’t this work?
<xsl:template name="checksite"> <xsl:choose> <xsl:when test="$root = 'http//www.abc.com'"> <xsl:variable name="site" select="'abc'" /> </xsl:when> <xsl:when test="$root = 'http//www.xyz.com'"> <xsl:variable name="site" select="'xyz'" /> </xsl:when> </xsl:choose> My variable is: <xsl:value-of select="$site" /> </xsl:template>I tried parameters, I tried variables, but all I get is an empty result or a XSLT error.
I want to set a parameter or variable which I can use throughout the template to perform certain XSLT actions if the site is ‘abc’ or the site is ‘xyz’.