我正在尝试使用类型来选择作为子类型的元素,因此我有一个包含 xs:integer 和 xs:float 子类型的测试文档。
如何告诉 XQuery 使用我的模式中定义的类型?
(我使用 oXygen 和 Saxon-SA 可能是相关的)
输入文件:
<?xml version="1.0" encoding="UTF-8"?>
<root xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="test-inherit.xsd">
<int>4</int>
<rest-int>5</rest-int>
<rest-float>6</rest-float>
</root>
WXS 架构:
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="root">
<xs:complexType>
<xs:sequence>
<xs:element name="int" type="xs:integer"/>
<xs:element name="rest-int" type="rest-int"/>
<xs:element name="rest-float" type="rest-float"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:simpleType name="rest-int">
<xs:restriction base="xs:integer">
<xs:maxInclusive value="10"></xs:maxInclusive>
<xs:minInclusive value="0"></xs:minInclusive>
</xs:restriction>
</xs:simpleType>
<xs:simpleType name="rest-float">
<xs:restriction base="xs:float">
<xs:maxInclusive value="10"></xs:maxInclusive>
<xs:minInclusive value="0"></xs:minInclusive>
</xs:restriction>
</xs:simpleType>
</xs:schema>
查询:
for $integer in doc("test-inherit.xml")//element(xs:integer)
return <integer>{$integer}</integer>