我不能以某种方式计算此 XSD 模式的提取中名称为“x”的兄弟元素的数量?
</xs:all>
<xs:assert test="count(./x) = 1"/>
</xs:complexType>
这应该计算我有多少“x”元素,但不知何故 Xerces J 只吐出: 输出:
Assertion evaluation ('count(./x) = 1') for element 'Properties' with type 'FF' did not succeed.
我做错了什么?断言失败的其他原因可能是什么?Elemen x 存在于定义中,也存在于 XML 中...???? 我需要命名空间或类似的东西吗?
我可以在一个简单的测试中重现正确的行为,但不适用于上面的复杂 XSD ......:
<Example>
<y/>
<y/>
<y/>
</Example>
XSD
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="Example" type="SS"/>
<xs:complexType name="SS">
<xs:all>
<xs:element name="y" maxOccurs="unbounded"/>
</xs:all>
<xs:assert test="count(y) = 3" />
</xs:complexType>
</xs:schema>
发现错误: 我认为,因为我有一个命名空间“sp”,所以我还需要将它提供给 XPath 以使其正常工作:
<xs:assert test="count(./sp:y) = 3" />