如何访问 XSD 断言 XPath 中的父元素? [英] How to access parent element in XSD assertion XPath?

查看:24
本文介绍了如何访问 XSD 断言 XPath 中的父元素?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am trying to write an assertion that will make the values of @row and @column less than or equal to the values of @rows and @columns in the parent element <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.

Are my assertions in the wrong place? What XPath expression do I use to specify the parent node? My editor isn't letting me write ..@rows.

推荐答案

XPath 断言不能到达其上下文之外.

An assertion XPath cannot reach outside of its context.

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

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>

这篇关于如何访问 XSD 断言 XPath 中的父元素?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆