Hi Folks,
XML documents oftentimes contain a set of things – a set of books, a set of people, a set of transactions, etc.
Typically, a set isn’t allowed to contain just anything, the set must satisfy some constraints.
Constraints can be expressed in different ways. Perhaps one way is better than another? Perhaps one is more declarative, the other more imperative? Perhaps one is XMLish, the other not?
Example: Here is an XML document containing a set (of positive even numbers):
<numbers>
<number>0</number>
<number>2</number>
<number>4</number>
<number>6</number>
…
</numbers>
Here are two ways to specify the set:
1. Defining properties: identify the properties that each member of the set must have. In this example, each number must have these 2 properties:
The two properties can be expressed in Schematron:
<sch:rule context="number">
<sch:assert
test="xs:integer(.)
ge 0">
Property: to be a member of the set, the number must be positive.
</sch:assert>
<sch:assert
test="xs:integer(.)
mod 2 eq 0">
Property: to be a member of the set, the number must be even.
</sch:assert>
</sch:rule>
2. Generate set members: specify how to generate the members of the set. The set of positive even numbers can be generated this way:
-
0 is an element of the set.
-
If x is an element of the set, then x+2 is an element of the set. (Alternatively: if x is an element of the set, then x-2 is an element of the set)
-
Nothing else belongs to the set.
Generating the set’s members can be expressed in Schematron:
<sch:rule context="numbers">
<sch:assert
test="number[xs:integer(.)
eq 0]">
0 is in the set.
</sch:assert>
<sch:assert
test="every
$i in number[xs:integer(.) ne 0] satisfies
number[xs:integer(.) eq ($i - 2)]">
If i is in the set, then i-2 is in the set
</sch:assert>
</sch:rule>
Recap: We’ve seen two ways to specify (constrain) a set:
(a) State a property (or properties) that an object must have to qualify as a member of the set.
(b) Define a set of rules which generate its members.
Which way is better? Which is preferred? Which is more declarative? Which is more XMLish?
/Roger