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

Re: XSD 1.1 - assert a condition of a complex type dependingon

  • From: =?UTF-8?B?TWFpayBTdMKfw7xocmVuYmVyZw==?=<maik.stuehrenberg@uni-bielefeld.de>
  • To: Michael Kay <mike@saxonica.com>
  • Date: Fri, 23 Oct 2009 10:46:35 +0200

Re:  XSD 1.1 - assert a condition of a complex type dependingon
Hello Michael,

thank you very much for the quick response.

Michael Kay schrieb:
>>     <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:assert sees a tree fragment rooted at the element E whose type you are
> testing against. root(.) returns the root of this tree, that is, the element
> E. The idea is that validation of an element depends only on the content of
> that element, not on the context in which it appears. XSLT, for example,
> assumes that if you copy a valid element to a new tree, then it will still
> be valid (against the original type).
> 
>> 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).
>>

Thanks for the clarification, I guess I have to read the specs more
thoroughly.
> 
> You need to put the assertion at the level of the common ancestor: that is,
> identify the element that contains all the data needed to compute the
> assertion, and put the assertion on the type of that element.

That was an idea I had in mind, but I wasn't sure if the @test XPath
expression would really test for every single s child of segs.

So the correct assert would be inside the cd element:

<xs:element name="cd">
    <xs:complexType>
      <xs:sequence>
        <xs:element ref="pd" minOccurs="1" maxOccurs="unbounded"/>
        <xs:element ref="segs"/>
      </xs:sequence>
      <xs:assert test="pd/@start le segs/s/@start"/>
      <xs:assert test="pd/@end ge segs/s/@end"/>
    </xs:complexType>
  </xs:element>

But if I try that I still get two validation errors:

Element cd does not satisfy assertion pd/@end ge segs/s/@end
Element cd does not satisfy assertion pd/@start le segs/s/@start

I understand and agree that the value of the s/end attribute raises the
error but why does the start attribute's value?

In addition the problem with that solution is that the error is raised
for the common ancestor which makes it much harder to inspect the wrong
s element (if I imagine hundreds of s elements and only one is wrong...)
-- which was a reason why I tried to locate the assert elements
underneath the s element.

Again, thank you very much for your hints.

Best regards,

Maik Stührenberg


> 
> Regards,
> 
> Michael Kay
> http://www.saxonica.com/
> http://twitter.com/michaelhkay 
> 
> 



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