Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

XSD 1.1 alternative test the contents of text()

Tags:

xml

xsd-1.1

Here is what I would like to do:

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

This one for the default:

<width>100</width>

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 Reference

like image 410
ac3d912 Avatar asked Dec 02 '25 01:12

ac3d912


1 Answers

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

Solution

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>
like image 132
ac3d912 Avatar answered Dec 04 '25 21:12

ac3d912



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!