我有一个xsl:for-each
,它将多个不同的元素组合在一起,然后有条件地处理每个元素。例如:
<xsl:for-each select=".//del | .//sup | .//unc | .//gap">
<xsl:choose>
<xsl:when test="del"><xsl:text>Output foo del</xsl:text></xsl:when>
<xsl:when test="sup"><xsl:text>Output foo sup</xsl:text></xsl:when>
<xsl:when test="unc"><xsl:text>Output foo unc</xsl:text></xsl:when>
<xsl:when test="gap"><xsl:text>Output foo gap</xsl:text></xsl:when>
<xsl:otherwise><xsl:text>For each works, but the tests do not!</xsl:text></xsl:otherwise>
</xsl:choose>
<xsl:for-each>
<xsl:for-each>
正常工作,因为它输出很多<otherwise> For each works, but the tests do not!
我以某种方式误解了如何编写@test
来捕获每个元素?我认为这与当前情况有关?非常感谢。
最佳答案
我不确定您要实现什么目标,但是它不应该这样读吗?
<xsl:for-each select=".//del | .//sup | .//unc | .//gap">
<xsl:choose>
<xsl:when test="self::del"><xsl:text>Output foo del</xsl:text></xsl:when>
<xsl:when test="self::sup"><xsl:text>Output foo sup</xsl:text></xsl:when>
<xsl:when test="self::unc"><xsl:text>Output foo unc</xsl:text></xsl:when>
<xsl:when test="self::gap"><xsl:text>Output foo gap</xsl:text></xsl:when>
<xsl:otherwise><xsl:text>For each works, but the tests do not!</xsl:text></xsl:otherwise>
</xsl:choose>
<xsl:for-each>
或者,您必须声明
xmlns="http://www.w3.org/1999/XSL/Transform"
例如在choose
甚至for-each
之内。
关于xml - 使用xsl:choose从xsl:for-each测试结果时XSLT失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47954303/