Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


Re: Attribute use depending on another attribute value

From: George Cristian Bina <george@---------.--->
To: Michael Kay <mike@--------.--->
Date: 5/17/2007 8:43:00 PM
Here it is an working example of XML Schema with embedded ISO Schematron 
rules that allow the display attribute only if type is 1:

<?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 maxOccurs="unbounded" ref="test"/>
       </xs:sequence>
     </xs:complexType>
   </xs:element>
   <xs:element name="test">
     <xs:annotation>
       <xs:appinfo>
         <pattern xmlns="http://purl.oclc.org/dsdl/schematron" 
id="testDisplay">
         <rule context="test">
           <assert test="(@type!='1' and not(@display)) or 
@type='1'">The 'display' atribute can be used only if the value for the 
'type' attribute is 1!</assert>
         </rule></pattern>
       </xs:appinfo>
     </xs:annotation>
     <xs:complexType>
       <xs:attribute name="display" type="xs:NCName" use="optional"/>
       <xs:attribute name="type" use="required" type="xs:integer"/>
       <xs:attribute name="value" use="required" type="xs:integer"/>
     </xs:complexType>
   </xs:element>
</xs:schema>


Best Regards,
George
---------------------------------------------------------------------
George Cristian Bina - http://aboutxml.blogspot.com/
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
www.---.com


Michael Kay wrote:
> You can't: it's a classic example of a co-occurrence constraint, which XML
> Schema 1.0 doesn't support. Wait for 1.1, or use Relax NG or schematron, or
> change the attribute name from "type" to "xsi:type".
>  
> The content model for an element can only depend on the element name and the
> value of its xsi:type attribute.
>  
> Michael Kay
> http://www.saxonica.com/
> 
> 
>   _____  
> 
> From: xmlschema-dev-request@w... [mailto:xmlschema-dev-request@w...] On
> Behalf Of Jan Vosloo
> Sent: 17 May 2007 13:06
> To: xmlschema-dev@w...
> Subject: Attribute use depending on another attribute value
> 
> 
>   _____  
> 
> Click here to view our e-mail legal notice:
> http://www.mxit.co.za/pdfs/mxit_legal.pdf or call: +27 21 888 7000
> 
>   _____  
> 
> 
> Hi, 
> 
> I just want to know how I would do the following:
> 
>  
> 
> <root>
> 
>   <test type="1" value="1" display="disp"/>
> 
>   <test type="2" value="100" />
> 
> </root>
> 
>  
> 
> I want the 'display' attribute to be available for use depending on what the
> value for the 'type' attribute is.
> 
>  
> 
> How can I do this in a XSD (XML schema)??
> 
>  
> 
> Thanks you in advance  
> 
>  
> 
> 
> 
> Jan Vosloo | Developer
> 
> 
> Tel: +27 21 888 7000 | Fax: +27 21 883 8123 
> 
> 
> 
> 
>  
> 
> 

From andrew.j.welch@g... Thu May 17 14:46:02 2007
Received: from lisa.w3.org ([128.30.52.41])
	by frink.w3.org with esmtp (Exim 4.50)
	id 1Ho


transparent
Print
Mail
Like It
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent