How to access parent element in XSD assertion XPath?

早过忘川 提交于 2019-12-02 02:36:05

An assertion XPath cannot reach outside of its context.

So, move your assertion up to the structure element, and use an every ... satisfies assertion test:

<?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>
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!