XML.orgXML.org
FOCUS AREAS |XML-DEV |XML.org DAILY NEWSLINK |REGISTRY |RESOURCES |ABOUT
OASIS Mailing List ArchivesView the OASIS mailing list archive below
or browse/search using MarkMail.

 


Help: OASIS Mailing Lists Help | MarkMail Help

[Date Prev] | [Thread Prev] | [Thread Next] | [Date Next] -- [Date Index] | [Thread Index]
XSD 1.1 - assert a condition of a complex type depending on anotherelement's attribute value

Hello everyone,

since I'm trying to convert an XSD 1.0 + embedded Schematron schema into
 an XSD 1.1 schema I stumbled upon an error regarding an assert element.

I tried to read all the questions raised (and answered) on this list
regarding this topic so far without success. So if there was a
discussion already some time ago just give me a quick note when and I
will help myself with the list archive.

Here is a very simple schema demonstrating the problem (at least I hope
it does):

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema";
xmlns="http://www.example.org";
  targetNamespace="http://www.example.org";>
  <xs:element name="cd">
    <xs:complexType>
      <xs:sequence>
        <xs:element ref="pd" minOccurs="1" maxOccurs="unbounded"/>
        <xs:element ref="segs"/>
      </xs:sequence>
    </xs:complexType>
  </xs:element>
  <xs:element name="pd">
    <xs:complexType mixed="true">
      <xs:attribute name="start" type="xs:integer" use="required"/>
      <xs:attribute name="end" type="xs:integer" use="required"/>
    </xs:complexType>
  </xs:element>
  <xs:element name="segs">
    <xs:complexType>
      <xs:sequence>
        <xs:element ref="s" minOccurs="1" maxOccurs="unbounded"/>
      </xs:sequence>
    </xs:complexType>
  </xs:element>
  <xs:element name="s">
    <xs:complexType>
      <xs:attribute name="start" type="xs:integer" use="required"/>
      <xs:attribute name="end" type="xs:integer" use="required"/>
      <xs:assert test="@start ge root(.)/cd/pd/@start"/>
      <xs:assert test="@end le root(.)/cd/pd/@end"/>
    </xs:complexType>
  </xs:element>
</xs:schema>

The pd element has two integer attributes, start and end. The s element
which may occur several times as a child/children of the segs element
(which itself is a sibling of the before mentioned pd element) bears the
same attributes.

What I want is to assert that the value of the start attribute of each s
element is greater or equal than that of the start attribute of the pd
element (and vice versa for the end attribute).

Saxon-EE 9.2.0.2 states that the schema itself is correct.

I use a simple demo instance for testing my two assert elements:

<?xml version="1.0" encoding="UTF-8"?>
<cd xmlns="http://www.example.org";
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
  xsi:schemaLocation="http://www.example.org demo.xsd">
  <pd start="0" end="10"/>
  <segs>
    <s start="0" end="5"/>
    <s start="1" end="15"/>
  </segs>
</cd>

If my asserts are correct (which I doubt) then in my opinion the first s
element should be fine while the second element's end attribute should
raise a validation error.

Saxon-EE 9.2.0.2 reports four validation errors in total:

Element s does not satisfy assertion @start ge root(.)/cd/pd/@start
Element s does not satisfy assertion @end le root(.)/cd/pd/@end
Element s does not satisfy assertion @start ge root(.)/cd/pd/@start
Element s does not satisfy assertion @end le root(.)/cd/pd/@end

So as already stated my questions are as following:
- I assume I made a mistake in creating my assert elements (at least the
test XPath expression), if anyone could give me a hint I would be very
grateful.
- Just as a comprehension question since all examples I've seen so far
are created in respect to local asserts: Is it possible to create such a
constraint depending on an element (either complex or simple type)
created globally somewhere else (e.g. in the same schema instance or in
an external schema file which is imported or included)? Or is this out
of scope for XSD 1.1?

Best regards,

Maik Stührenberg



[Date Prev] | [Thread Prev] | [Thread Next] | [Date Next] -- [Date Index] | [Thread Index]


News | XML in Industry | Calendar | XML Registry
Marketplace | Resources | MyXML.org | Sponsors | Privacy Statement

Copyright 1993-2007 XML.org. This site is hosted by OASIS