Simple Types and Facets

A simple type describes text: an attribute value or a childless element. From the built-in types (those of XPath 3.1 Data Types) you derive your own by restriction with facets (pattern, enumeration, minInclusive, maxExclusive, totalDigits, fractionDigits, length, and assertion in 1.1), by list or by union:

types.xsd: money, ratings and code lists as restricted simple typesXML
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <xs:simpleType name="moneyType"><xs:restriction base="xs:decimal">
    <xs:minExclusive value="0"/><xs:totalDigits value="7"/><xs:fractionDigits value="2"/>
  </xs:restriction></xs:simpleType>
  <xs:simpleType name="ratingType"><xs:restriction base="xs:decimal">
    <xs:minInclusive value="0"/><xs:maxInclusive value="5"/><xs:fractionDigits value="1"/>
  </xs:restriction></xs:simpleType>
  <xs:simpleType name="availabilityType"><xs:restriction base="xs:token">
    <xs:enumeration value="in-stock"/><xs:enumeration value="out-of-stock"/>
  </xs:restriction></xs:simpleType>
  <xs:simpleType name="roleType"><xs:restriction base="xs:token">
    <xs:enumeration value="author"/><xs:enumeration value="editor"/>
  </xs:restriction></xs:simpleType>
</xs:schema>

Facets combine (a price must satisfy all three), enumerations are case-sensitive, and a pattern always matches the whole value, never a substring.