检查元素中的所有值是否相同 [英] Checking all values in the element are same
问题描述
我有一个类似的xml,值可以是
I have an xml like, values can be
<n1>value1</n1>
<n1>value1</n1>
<n1>value2</n1>
我需要检查所有这些值是否相同,如果相同,我需要将其分配给另一个元素.我使用的是 XSLT v1.0.
I need to check if all these values are same and if same I would need to assign it to another element. I am using XSLT v1.0.
谢谢,
推荐答案
好问题,+1.
只需使用:
not(/*/n1[1] != /*/n1)
假设在名为 $v
的变量中选择了所有 n1
元素,这可以用仅 14 个字符长的 XPath 表达式来表示:
Assuming that all n1
elements are selected in a variable named $v
, this can be expressed in just 14 characters-long XPath expression:
not($v[1] != $v)
解释 1:
根据定义:
/*/n1[1] != /*/n1
is true()
如果/*/n1
中存在一个节点,其字符串值不等于 /*/的字符串值n1[1]
is true()
exactly if there exists a node in /*/n1
whose string value isn't equal to the string value of /*/n1[1]
逻辑否定:
not(/*/n1[1] != /*/n1)
is true()
当 /*/n1
中的 no 节点存在其字符串值不等于 /*/n1[1]
-- 也就是说,如果 /*/n1
中的所有节点都具有相同的 sting 值.
is true()
iff no node in /*/n1
exists whose string value isn't equal to the string value of /*/n1[1]
-- that is, if all nodes in /*/n1
have the same sting value.
解释 2:
这遵循更一般的双重否定法则:
every x has property y
相当于:
There is no x that doesn't have property y
这篇关于检查元素中的所有值是否相同的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!