Assertions and CTA

Assertions and Conditional Type Assignment

XSD 1.1's xs:assert attaches an XPath 2.0 test to a complex type ($value holds simple content). It sees only its own subtree, so cross-record rules stay with Schematron. Conditional type assignment lists xs:alternative types: the first whose test on the element's attributes is true applies, and each must derive from the declared type. catalog11.xsd layers both onto catalog.xsd with xs:override, which replaces the global identifier: a SKU must match BN-\d{4}, an ISBN-13 its check digit:

catalog11.xsd: an ISBN checksum assertion and alternatives for identifierXML
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <xs:override schemaLocation="catalog.xsd">
    <xs:element name="identifier" type="idType">
      <xs:alternative test="@type = 'isbn13'" type="isbnIdType"/>
      <xs:alternative type="skuIdType"/>
    </xs:element>
  </xs:override>
  <xs:complexType name="skuIdType"><xs:simpleContent><xs:restriction base="idType">
    <xs:pattern value="BN-\d{4}"/></xs:restriction></xs:simpleContent></xs:complexType>
  <xs:complexType name="isbnIdType"><xs:simpleContent><xs:restriction base="idType">
    <xs:pattern value="97[89]\d{10}"/>
    <xs:assert test="sum(for $i in 1 to 13 return xs:integer(substring($value, $i, 1))
                     * (if ($i mod 2) then 1 else 3)) mod 10 eq 0"/>
  </xs:restriction></xs:simpleContent></xs:complexType>
</xs:schema>

xmllint 3,427 stops at "element override: Schemas parser error", so these rules need a 1.1 processor (Validating with an XSD). libxml2 3,427 also ignores vc:minVersion="1.1", meant to hide 1.1 parts from 1.0 processors, so keep 1.1 rules in a separate layer as here.