如何在XSL中测试缺少的属性?

时间:2022-05-24 20:35:44

What I have is following:

我所拥有的是:

<xsl:variable name="myvar" select=".//spss:category[((not @varName) or @varName=$colVarName) and @text=$series]/spss:cell/@text"/>

What it should do is select the text of the spss:cell's text-Attribute as long as it is a child of a spss:category that has

它应该做的是选择spss:cell的text-Attribute的文本,只要它是一个spss:child的子类。

  • either a varName Attribute with a value equal to $colVarName
  • 一个varName属性,其值等于$ colVarName

  • OR no varName Attribute at all
  • 或者根本没有varName属性

What is happening is following error message (sorry translating here, so just the gist of it):

正在发生的是关注错误消息(抱歉在这里翻译,所以只是它的要点):

Expected Token ')'. Found Token '@'.
.//spss:category[((not -->@<-- varName) or @varName=$colVarName...

预期令牌')'。找到令牌'@'。 .//spss:category {((not - > @ < - varName)或@ varName = $ colVarName ...

Problem Solved! (See below)

问题解决了! (见下文)

2 个解决方案

#1


OK, I think I found the mistake:

好吧,我想我发现了错误:

not must be used with parenthesis, so instead of

不能用括号,所以代替

(not @varName) or @varName=$colVarName

it should have been

应该是的

not(@varName) or @varName=$colVarName

#2


indeed - not() is a function that returns the boolean opposite of whatever is between the parens. If necessary - it will cast its argument to a boolean. In this case, an empty node set casts automatically to false, so if @varName gives you an empty node set, not(@varName) will be true.

确实 - not()是一个函数,它返回与parens之间的任何东西相反的布尔值。如有必要 - 它会将其参数转换为布尔值。在这种情况下,空节点集会自动转换为false,因此如果@varName为您提供空节点集,则不会(@varName)为true。

#1


OK, I think I found the mistake:

好吧,我想我发现了错误:

not must be used with parenthesis, so instead of

不能用括号,所以代替

(not @varName) or @varName=$colVarName

it should have been

应该是的

not(@varName) or @varName=$colVarName

#2


indeed - not() is a function that returns the boolean opposite of whatever is between the parens. If necessary - it will cast its argument to a boolean. In this case, an empty node set casts automatically to false, so if @varName gives you an empty node set, not(@varName) will be true.

确实 - not()是一个函数,它返回与parens之间的任何东西相反的布尔值。如有必要 - 它会将其参数转换为布尔值。在这种情况下,空节点集会自动转换为false,因此如果@varName为您提供空节点集,则不会(@varName)为true。