我知道这可能看起来像一个愚蠢/新手的问题,但我对XSLT来说相当新手(虽然我已经开始接触它并看到它的功能).
何时适合使用xsl:if和when何时适合使用xsl:choose/xsl:when?
当我想要一个"其他"选项时,我一直在使用选择/何时/否则.它是否正确?
例如,我有一些我正在做的地方:
<xsl:choose>
<xsl:when test="count(entry) != 0">
put positive outcome here
</xsl:when>
<xsl:otherwise>
put something else here
</xsl:otherwise>
</xsl:choose>
Run Code Online (Sandbox Code Playgroud)
将xsl:如果更好?
感谢您的投入.
使用xsl:if简单的情况下,你只是想测试一个表达式为true.(注意没有相应的xsl:else.)
<xsl:if test="expression">
output if the expression is true
</xsl:if>
Run Code Online (Sandbox Code Playgroud)
使用xsl:choose了,你有一些备用输出时的表情是假案.
<xsl:choose>
<xsl:when test="expression">
output if the expression is true
</xsl:when>
<xsl:otherwise>
output if the expression is false
</xsl:otherwise>
</xsl:choose>
Run Code Online (Sandbox Code Playgroud)