gpt4 book ai didi

xml - 如何访问 XSD 断言 XPath 中的父元素?

转载 作者:行者123 更新时间:2023-12-03 16:10:00 25 4
gpt4 key购买 nike

我正在尝试编写一个断言,使 @row 的值变为和 @column小于或等于 @rows 的值和 @columns在父元素中 <structure> .

<xs:element name="structure">
<xs:complexType>
<xs:sequence>
<xs:element name="cell" maxOccurs="unbounded">
<xs:complexType>
<xs:attribute name="row" type="xs:positiveInteger"/>
<xs:attribute name="column" type="xs:positiveInteger"/>
<xs:assert test="@row le @rows"/>
<xs:assert test="@column le @columns"/>
</xs:complexType>
</xs:element>
</xs:sequence>
<xs:attribute name="rows" type="xs:positiveInteger" use="optional"/>
<xs:attribute name="columns" type="xs:positiveInteger" use="optional"/>
</xs:complexType>
</xs:element>

我的断言在错误的地方吗?我使用什么 XPath 表达式来指定父节点?我的编辑不让我写 ..@rows .

最佳答案

断言 XPath 无法到达其上下文之外。

因此,将您的断言移至 structure 元素,并使用 every ... satisfies 断言测试:

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:vc="http://www.w3.org/2007/XMLSchema-versioning"
elementFormDefault="qualified"
vc:minVersion="1.1">
<xs:element name="structure">
<xs:complexType>
<xs:sequence>
<xs:element name="cell" maxOccurs="unbounded">
<xs:complexType>
<xs:attribute name="row" type="xs:positiveInteger"/>
<xs:attribute name="column" type="xs:positiveInteger"/>
</xs:complexType>
</xs:element>
</xs:sequence>
<xs:attribute name="rows" type="xs:positiveInteger" use="optional"/>
<xs:attribute name="columns" type="xs:positiveInteger" use="optional"/>
<xs:assert test="every $r in cell/@row satisfies @rows >= $r"/>
<xs:assert test="every $c in cell/@column satisfies @columns >= $c"/>
</xs:complexType>
</xs:element>
</xs:schema>

关于xml - 如何访问 XSD 断言 XPath 中的父元素?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37176384/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com