library

Table of Contents

Declaration
Related GitHub issue(s)
Sample usage
Commentary

Element context(s)

Clause 5.4.8 (library element)

The library element is an allowed root element containing external declarations, including abstract rules [...] and patterns [...].The contents of this element can be included in a schema by using extends.

Declaration

element library {
        attribute id { xsd:ID }?,
        rich,
        (foreign
         & (inclusion | extends)*
         & (title?, p*, param*, let*, abstract-rules*, (rule-set|pattern)*, p*, diagnostics?, properties?))
    }

Related GitHub issue(s)

A library system for abstract patterns and abstract rule-sets

Sample usage

Example 13. library element

Given this schema:

<sch:schema xmlns:sch="http://purl.oclc.org/dsdl/schematron" queryBinding="xquery">
  <sch:extends href='library.sch'/>
  <sch:pattern>
    <sch:rule context="/">
      <sch:assert test="true()">Always true</sch:assert>
    </sch:rule>
  </sch:pattern>
</sch:schema>

and the library imported via extends from library.sch (see highlight above):

<library xmlns="http://purl.oclc.org/dsdl/schematron" queryBinding="xquery">
    <pattern id='blort'>
        <rule context="blort">
            <assert test="@wibble">Element <name/> must have attribute 'wibble'</assert>
        </rule>
    </pattern>    
    <pattern id='wibble'>
        <rule context="wibble">
            <assert test=". = $some-global">Element <name/> must have value '<value-of select="$some-global"/>'</assert>
        </rule>
    </pattern>    
</library>

the contents of the library will be included in place of the extends element, to produce the resulting schema:

<sch:schema xmlns:sch="http://purl.oclc.org/dsdl/schematron" queryBinding="xquery">
  <pattern xmlns="http://purl.oclc.org/dsdl/schematron" id="blort">
        <rule context="blort">
            <assert test="@wibble">Element <name/> must have attribute 'wibble'</assert>
        </rule>
    </pattern>
  <pattern xmlns="http://purl.oclc.org/dsdl/schematron" id="wibble">
        <rule context="wibble">
            <assert test=". = $some-global">Element <name/> must have value '<value-of select="$some-global"/>'</assert>
        </rule>
    </pattern>
  <sch:pattern>
    <sch:rule context="/">
      <sch:assert test="true()">Always true</sch:assert>
    </sch:rule>
  </sch:pattern>
</sch:schema>

Commentary

This element is a convenience for building modular schemas, featuring a pared-down version of element schema's content model.