XSLT:如何在“选择,何时,测试”语法的同一个测试中选择多个条件?

时间:2018-09-26 04:19:17

标签: xslt

我需要验证XSLT中的多个条件,但没有找到关于此主题的确切问题。有人可以帮我举一些例子吗?我想在测试中添加测试以验证更多情况。我的例子不起作用。

                <td align="center" style="font-size=8pt">
                    <xsl:choose>
                        <xsl:when test="esp:DocType[@v='T2']", test="esp:BusType[@v='44']">first</xsl:when>
                        <xsl:otherwise>
                            <xsl:value-of select="esp:AccPnt/@v"/>
                        </xsl:otherwise>
                    </xsl:choose>
                </td>

<td align="center" style="font-size=8pt">
                    <xsl:choose>
                        <xsl:when test="esp:DocType[@v='T2'], esp:BusType[@v='44']">first</xsl:when>
                        <xsl:otherwise>
                            <xsl:value-of select="esp:AccPnt/@v"/>
                        </xsl:otherwise>
                    </xsl:choose>
                </td>

2 个答案:

答案 0 :(得分:0)

XPath具有布尔运算符。

<td align="center" style="font-size=8pt">
    <xsl:choose>
        <xsl:when test="esp:DocType[@v='T2'] and esp:BusType[@v='44']">first</xsl:when>
        <xsl:otherwise>
            <xsl:value-of select="esp:AccPnt/@v"/>
        </xsl:otherwise>
    </xsl:choose>
</td>

上面的方法有效,但起初可能不是很明显:它比较两个节点集的空度。空节点集在布尔上下文中计为false,已填充节点集计为true。因此左侧esp:DocType[@v='T2']是否选择一个节点,即,仅在其esp:DocType属性值等于{{1}时选择@v }。当表达式的另一半也选择一个节点时,总结果将为'T2'

更明显的写同一件事的方法是:

true

答案 1 :(得分:0)

在阅读您的问题时,每个还是任何都不清楚 这些xsl:when说明中应满足您的条件。

在第一种情况下,应将放在这些条件之间, 而在第二种情况下为

很明显, Tomalak 考虑了“每件”案件,因此他写道 condition_1 condition_2 ,但是我对此不太确定。

相关问题