gpt4 book ai didi

xml - XSD 1.1 替代测试 text() 的内容

转载 作者:行者123 更新时间:2023-12-01 23:45:07 25 4
gpt4 key购买 nike

这是我想做的:

<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>

这应该适用于第一个备选方案(但不是):

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

这是默认的:

<width>100</width>

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

W3 Reference

最佳答案

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

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]).

看来它不允许您针对其文本节点(或任何其他子节点)进行测试。

解决方案

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

<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>

关于xml - XSD 1.1 替代测试 text() 的内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29709465/

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