xml IF 语句是否允许 XSLT 中的 OR 条件?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10942585/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-06 13:31:43  来源:igfitidea点击:

Is IF statement allow OR condition in XSLT?

xmlxslt

提问by mrrsb

how to test if my condition is this;

如何测试我的情况是否是这样;

<xsl:if test="node = '1' or node='2'">
<input name="list_{@id}" value="{@id}" type="checkbox"/>
</xsl:if>

Is IF statement allowed OR condition? Please advice..

IF 语句是否允许 OR 条件?请指教..

采纳答案by Dimitre Novatchev

Is IF statement allowed OR condition?

IF 语句是否允许 OR 条件?

No, but XPath has an oroperator -- do note that XPath is case-sensitive language.

不,但 XPath 有一个or运算符——请注意 XPath 是区分大小写的语言。

The XPath expression in the provided code:

提供的代码中的 XPath 表达式

node = '1' or node='2'

is syntactically correct.

语法正确

oris a standard XPath operatorand can be used to combine two subexpressions.

or标准的 XPath 运算符,可用于组合两个子表达式

[33] OperatorName ::= 'and' | 'or' | 'mod' | 'div'

[33] OperatorName ::= 'and' | '或' | '模式' | 'div'

Here is a complete XSLT transformation example:

这是一个完整的 XSLT 转换示例:

<xsl:stylesheet version="1.0"
 xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
 <xsl:output omit-xml-declaration="yes" indent="yes"/>
 <xsl:strip-space elements="*"/>

 <xsl:template match="node()|@*">
  <xsl:copy>
   <xsl:apply-templates select="node()|@*"/>
  </xsl:copy>
 </xsl:template>

 <xsl:template match="num[ . = 3 or . = 5]"/>
</xsl:stylesheet>

When this transformation is applied on the following XML document:

当此转换应用于以下 XML 文档时

<nums>
  <num>01</num>
  <num>02</num>
  <num>03</num>
  <num>04</num>
  <num>05</num>
  <num>06</num>
  <num>07</num>
  <num>08</num>
  <num>09</num>
  <num>10</num>
</nums>

the wanted, correct result is produced (all elements copied with the exception of <num>03</num>and <num>05</num>:

产生了想要的、正确的结果(除了<num>03</num>and之外的所有元素都被复制了<num>05</num>

<nums>
   <num>01</num>
   <num>02</num>
   <num>04</num>
   <num>06</num>
   <num>07</num>
   <num>08</num>
   <num>09</num>
   <num>10</num>
</nums>

回答by Oleksi

You can use or just like you did in your example. Hereare the supported operators in XSLT.

您可以使用或就像您在示例中所做的那样。以下是 XSLT 中支持的运算符。