[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Datatypes in Schematron (was Re: Namespaces,W3C XML Schema (was Re: ANN: SAX Filters forNamespaceProcessing))
- From: Rick Jelliffe <email@example.com>
- To: Xml-Dev <firstname.lastname@example.org>
- Date: Thu, 23 Aug 2001 13:54:19 +1000
> >Elliotte Rusty Harold wrote:
> On the other hand, over the last three years as I've taught developers about DTDs, almost invariably the first question is "How do I say that an element contains an int?" and the second question is usually ""How do I say that an element contains a year since 1969?" or some variant thereof.
In Schematron (untested), I think it would be something like this:
<title>For Rusty's Inquiring Students</title>
<p>This is an example of creating a datatype using Schematron's "abstract rules"
and using them. </p>
<!-- Define an abstract rule on a data value (i.e. a type) for int -->
<rule abstract="true" id="int">
<assert test="string-length(string-normalize(./text())) > 0"
>This element must contain a value.</assert>
>This element should contain an int. An int it a number.</assert>
<assert test="floor(number(./text())) = ceiling(number(./text())) "
>This element should contain an int. An int is a whole number.</assert>
<assert test="number(./text()) < 2147483647"
>This element should contain an int. An int is less than 2^31-1.</assert>
<assert test="number(./text()) >= -2147483648"
>This element should contain an int. An int is greater than -(2^31).</assert>
<!-- Make the assertions -->
<rule context="someElement" >
<extends rule="int" />
<extends rule="int" />
<assert test="number(./text()) > 1969"
>This element should contain a year since 1969</assert>
Most other schema languages have built-in types. I guess that since people will
tend to evaluate schema languages using a check-box, they might put
"no datatyping" on Schematron, when really they mean no "built-in"
data types (apart from the XPath ones: number, string, boolean).
With Schematron's approach, you can restrict a datatype
merely by providing extra assertions before or after the <extend>
element. (You can over-ride datatype checking by catching the
text in a previous rule: this is not type extension by allowing
type exceptions, I guess.)