XML
<Categories>
<category>
<blog>ABC</blog>
<link>open</link>
<link1>close</link1>
</category>
</Categories>
XSLT
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0">
<xsl:template match="category">
<xsl:variable name="openCloseValidation">
<xsl:value-of select="link" />
</xsl:variable>
<xsl:variable name="holidayValidation">
<xsl:value-of select="link1" />
</xsl:variable>
<h1><xsl:value-of select="normalize-space($openCloseValidation)" /></h1>
<h1><xsl:value-of select="normalize-space($holidayValidation)" /></h1>
<xsl:choose>
<xsl:when test="contains($openCloseValidation, 'open')">
<xsl:if test="not(contains($holidayValidation, 'close'))">
<xsl:value-of select="'true'" />
</xsl:if>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="'false'" />
</xsl:otherwise>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>
第一个条件不满足但是它没有进入否则阻止并显示错误。
如果这里有问题,你可以告诉我吗?
答案 0 :(得分:4)
满足第一个xsl:when
条件,因为contains($openCloseValidation, 'open')
为真。但是在你的xsl:when
内你有一个xsl:if
,如果失败了,那么什么都不会输出。
你应该把它重写为......
<xsl:choose>
<xsl:when test="contains($openCloseValidation, 'open') and not(contains($holidayValidation, 'close'))">
<xsl:value-of select="'true'" />
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="'false'" />
</xsl:otherwise>
</xsl:choose>
顺便说一句,编写变量声明就好了......
<xsl:variable name="openCloseValidation" select="link" />