OASIS Mailing List ArchivesView the OASIS mailing list archive below
or browse/search using MarkMail.

 


Help: OASIS Mailing Lists Help | MarkMail Help

 


 

   Re: XML Schema and context-senstive datatyping

[ Lists Home | Date Index | Thread Index ]
  • From: Rick JELLIFFE <ricko@geotempo.com>
  • To: ",xml-dev" <xml-dev@lists.xml.org>
  • Date: Wed, 04 Oct 2000 23:42:59 +0800

Sam Hunting wrote:
> 
> If this is a FAQ I apologize in advance.
> 
> Suppose I have an address that can look like this:
> 
>     <Address>
>         <PostalCode>12345-6789</PostalCode>
>         <CountryCode>US</CountryCode>
>     </Address>
> 
> but can also look like this:
> 
>     <Address>
>         <PostalCode>H3H-2A6</PostalCode>
>         <CountryCode>CA</CountryCode>
>     </Address>
> 
> and I want to change the datatype of <PostalCode> based on the value of
> <CountryCode> so I can validate the user's entries, can I do that using
> XML Schema? If so, how?
> 
> (One would wish to validate a Zip code for the USA, but a Canadian
> Postal Code for Canada. The dataype of country code would be an
> enumerated list a la ISO 3166.
 
No.

To do this you should create a simple XSLT null transformation which
decorates the PostalCode attribute with the information it needs.
Something like:

  <xslt:template  match="Address[CountryCode/text()='CA']>
     <Address>
        <PostalCode xsi:type="PostalCodeCA">H3H-2A6</PostalCode>
        <CountryCode>CA</CountryCode>
     </Address>
  </xslt:template>

Then make an XML Schema with that particular simple type PostallCodeCA.

In XML Schemas, there is no interaction between type and data or
attribute values. All typing comes from an element's context (limited to
its its name or parent's type or perhaps its predecessors). 


You could also make a Schematron schema with something like:
  <rule context="Address/PostalCode[../CountryCode='CA']">
    <assert test="string-length(.) = 7">
     Canadian codes are 7 chars long (are they?)
    </assert>
    ...
   </rule>
where you can put other lexical checks in further rules statements.

Cheers

Rick Jelliffe




 

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

Copyright 2001 XML.org. This site is hosted by OASIS