[XML-DEV Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

XSD 1.1 - assert a condition of a complex type depending on anothereleme

  • From: =?UTF-8?B?TWFpayBTdMKfw7xocmVuYmVyZw==?=<maik.stuehrenberg@uni-bielefeld.de>
  • To: xml-dev@lists.xml.org
  • Date: Fri, 23 Oct 2009 10:08:34 +0200

XSD 1.1 - assert a condition of a complex type depending on anothereleme
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]


PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
 

Stylus Studio has published XML-DEV in RSS and ATOM formats, enabling users to easily subcribe to the list from their preferred news reader application.


Stylus Studio Sponsored Links are added links designed to provide related and additional information to the visitors of this website. they were not included by the author in the initial post. To view the content without the Sponsor Links please click here.

Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.