XSD 1.1 替代测试 text() 的内容 [英] XSD 1.1 alternative test the contents of text()

查看:23
本文介绍了XSD 1.1 替代测试 text() 的内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我想要做的:

<xs:element name="width">
  <!-- If the value is auto, then it can have min/max attribs -->
  <xs:alternative test="text() eq auto" type="heightWidthAutoType" />
  <!-- Otherwise it is treated as a normal positionType -->
  <xs:alternative type="positionType" />
</xs:element>    

这应该适用于第一个选择(但不适用):

This should apply to the first alternative (but doesn't):

<width min='100' max='100'>auto</width>

这是默认的:

<width>100</width>

无论我为标签的内容输入什么,它总是选择默认值.我假设 text() 在替代方案中无效,但我似乎无法找到说明这一点的文档.

No matter what I put in for the contents of the tag, it always chooses the default. I'm assuming text() isn't valid in an alternative, but I can't seem to find the documentation saying that.

W3 参考

推荐答案

所以我回去实际阅读了细节(而不是略读)...

So I went back and actually read the details (instead of skimming)...

1 An instance of the [XDM] data model is constructed as follows:
1.1 An information set is constructed by copying the base information set
    properties (and not any of the properties specific to ·post-schema-
    validation infoset·) of the following information items:
1.1.1 E itself.
1.1.2 E's [attributes] (but not its [children]).

因此它似乎不允许您针对其文本节点(或任何其他子节点)进行测试.

So it appears that it doesn't allow you to test against its text node (or any other children).

解决方案

这是我最终解决问题的方法:

Here's how I ended up solving my problem:

<xs:element name="width" type="heightWidthType" />
<xs:element name="height" type="heightWidthType" />

<xs:complexType name="heightWidthType">
    <xs:simpleContent>
        <xs:extension base="positionType">
            <!-- These are actually only valid if the value of the element is auto -->
            <xs:attribute name="min" type="xs:unsignedInt" />
            <xs:attribute name="max" type="xs:unsignedInt" />
            <xs:assert test="not((@min or @max)) or ((@min or @max) and $value eq 'auto')" />
        </xs:extension>
    </xs:simpleContent>
</xs:complexType>

<xs:simpleType name="positionType">
    <xs:restriction base="xs:string">
        <!--  If an "r" is included (eg 180r) then the measurement is taken from the parent's right edge (in the left direction). -->
        <xs:pattern value="-?\d+(\.\d+)?(r|%)?" />
        <xs:pattern value="auto" />
    </xs:restriction>
</xs:simpleType>

这篇关于XSD 1.1 替代测试 text() 的内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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