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

Re: XML Schema and context-senstive datatyping

  • From: Rick JELLIFFE <ricko@g...>
  • To: ",xml-dev" <xml-dev@l...>
  • Date: Wed, 04 Oct 2000 23:42:59 +0800

xslt null transformation
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

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.