如何在<xsl:if>的'test'属性表达式中添加多个测试条件标签 [英] How to add multiple test conditions in 'test' attribute expression of <xsl:if> tag

查看:27
本文介绍了如何在<xsl:if>的'test'属性表达式中添加多个测试条件标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有可能在 XSLT 的 <xsl:if> 标签中的 'test' 属性表达式中包含多个条件,例如

Is there any possibility to include multiple conditions in 'test' attribute expression in <xsl:if> tag of XSLT like

<xsl:if test="$var='ab' | $var='bc' | $var='ca' ">
</xsl:if>

我收到一个错误表达式必须评估为节点集".

I am getting an error as "Expression must be evaluated to a node-set".

有没有可能在<xsl:if>标签中编码这样多个条件?

Is there any possibility to code such multiple conditions in <xsl:if> Tag?

谁能解释一下我们如何为以下标签实现多条件验证

Can anyone explain how can we achieve this multiple condition validation for the following tags in

在测试属性表达式中

在选择属性表达式中

在匹配属性表达式中

?

推荐答案

<xsl:if test="$var='ab' | $var='bc' | $var='ca' ">

这是错误的 -- 您正在对布尔值使用 XPath union 运算符 |.

This is wrong -- you are using the XPath union operator | on boolean values.

解决方案:使用 XPath or 运算符:

Solution: use the XPath or operator:

<xsl:if test="$var='ab' or $var='bc' or $var='ca' ">

可以优化上面的XPath表达式(test属性的值),这样只做一次比较,不需要or:

The above XPath expression (the value of the test attribute) can be optimized, so that only one comparison is made and no or is necessary:

<xsl:if test="contains('|ab|bc|ca|', concat('|', $var, '|'))">

这篇关于如何在&lt;xsl:if&gt;的'test'属性表达式中添加多个测试条件标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆