xml XSLT if 表达式语法,组合多个表达式
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10604973/
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
XSLT if expression syntax, combining more than one expression
提问by SuckerForMayhem
Trying to combine an if statement using <xsl:if test="expression">where I want to have multiple expressions together, to do order of operations such as this psuedocode:
尝试使用<xsl:if test="expression">我想要将多个表达式放在一起的地方组合 if 语句,以执行诸如此伪代码之类的操作顺序:
if (Number != '' and (Name != '' or PreferredName != '')) {// code here}
Essentially I want to do this in an <xsl:if>:
基本上我想在一个<xsl:if>:
<xsl:if text="Number != '' and (Name != '' or PreferredName != '')">
but I'm not sure of the expressionsyntax, I don't think I can do the ()like that, as I haven't seen it anywhere. I couldn't find the expression syntax on the web easily, it may be XPath, but I'm not sure if XPath supports ()to group expressions. I'm not an expert on XSL/XML/XSD's' so I don't know if the expression is even XPath, or what.
但我不确定expression语法,我认为我不能这样做(),因为我在任何地方都没有见过。我在网上找不到表达式语法,可能是 XPath,但我不确定 XPath 是否支持()对表达式进行分组。我不是 XSL/XML/XSD 的专家,所以我不知道该表达式是否是 XPath 或什么。
I'd rather not do nested <xsl:if>statements if possible, and want to stick with <xsl:if>not <xsl:choose>.
<xsl:if>如果可能的话,我宁愿不做嵌套语句,并且想坚持使用<xsl:if>not <xsl:choose>。
I'm sure this is probably a simple answer, but kind of stuck here. Thanks.
我确定这可能是一个简单的答案,但有点卡在这里。谢谢。
回答by Maestro13
The conditional statement xsl:iffor starters needs an xsl:templateor other xsl element as parent.
The syntax will become similar to the following:
xsl:ifstarters的条件语句需要一个xsl:template或其他 xsl 元素作为父元素。
语法将类似于以下内容:
<xsl:template>
... preliminary xsl statements ...
<xsl:if test="Number != '' and (Name != '' or PreferredName != '')">
... further xsl statements (the code you were referring to ...
</xsl:if>
... other xsl stataments ...
</xsl:template>
Further advise: study xslt usage, in particular templates and their application (and sort of automatic looping).
进一步建议:研究 xslt 的用法,特别是模板及其应用程序(以及某种自动循环)。

