views:

340

answers:

2

Let's say I have the string of "2004,2005,2006,2007,2008,2009" that is assigned to the parameter of "show".

Now, this does work:

<xsl:if test="$show='2004'">
    //stuff
</xsl:if>

This doesn't work:

<xsl:if test="$show='2005'">
    //stuff
</xsl:if>

I'm not sure how to test for part of a string like that. Any idea?

+2  A: 

Use contains.

<xsl:if test="contains($show, '2004')">
    //stuff
</xsl:if>

A more detailed example, which will print yes.

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"&gt;
    <xsl:template match="/">
        <xsl:variable name="show" select="'2004,2005,2006,2007,2008,2009'"/>
        <xsl:if test="contains($show, '2004')">yes</xsl:if>
        <xsl:if test="not(contains($show, '2004'))">no</xsl:if>
    </xsl:template>
</xsl:stylesheet>
lavinio
+1  A: 

You're needing the contains() XPath function. You can use it like this:

<xsl:if test="contains($show,'2005')">
  //stuff
</xsl:if>
pixel