5 string testing xslt parameters
假设我将"2004,2005,2006,2007,2008,2009"字符串分配给"show"参数.
现在,这确实有效:
<xsl:if test="$show='2004'">
//stuff
</xsl:if>
Run Code Online (Sandbox Code Playgroud)
这不起作用:
<xsl:if test="$show='2005'">
//stuff
</xsl:if>
Run Code Online (Sandbox Code Playgroud)
我不确定如何测试这样的字符串的一部分.任何的想法?
lav*_*nio 19
使用contains.
<xsl:if test="contains($show, '2004')">
//stuff
</xsl:if>
Run Code Online (Sandbox Code Playgroud)
更详细的例子,这将打印肯定.
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<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>
Run Code Online (Sandbox Code Playgroud)