summaryrefslogtreecommitdiff
path: root/src/lxml/isoschematron
diff options
context:
space:
mode:
authorscoder <none@none>2009-12-30 14:57:53 +0100
committerscoder <none@none>2009-12-30 14:57:53 +0100
commita9144fcdde863301564b2a4b63c47ba2681dc076 (patch)
treef6a3175087e75aa495b4b1f1b5d17fdc97c87e9a /src/lxml/isoschematron
parent812653bfb5bcab26abe8b8e255da8c9f7df75670 (diff)
downloadpython-lxml-a9144fcdde863301564b2a4b63c47ba2681dc076.tar.gz
[svn r4305] merge iso-schematron branch
--HG-- branch : trunk
Diffstat (limited to 'src/lxml/isoschematron')
-rw-r--r--src/lxml/isoschematron/__init__.py277
-rw-r--r--src/lxml/isoschematron/resources/rng/iso-schematron.rng622
-rw-r--r--src/lxml/isoschematron/resources/xsl/RNG2Schtrn.xsl75
-rw-r--r--src/lxml/isoschematron/resources/xsl/XSD2Schtrn.xsl77
-rw-r--r--src/lxml/isoschematron/resources/xsl/iso-schematron-xslt1/iso_abstract_expand.xsl296
-rw-r--r--src/lxml/isoschematron/resources/xsl/iso-schematron-xslt1/iso_dsdl_include.xsl1160
-rw-r--r--src/lxml/isoschematron/resources/xsl/iso-schematron-xslt1/iso_schematron_message.xsl55
-rw-r--r--src/lxml/isoschematron/resources/xsl/iso-schematron-xslt1/iso_schematron_skeleton_for_xslt1.xsl1796
-rw-r--r--src/lxml/isoschematron/resources/xsl/iso-schematron-xslt1/iso_svrl_for_xslt1.xsl588
-rw-r--r--src/lxml/isoschematron/resources/xsl/iso-schematron-xslt1/readme.txt83
10 files changed, 5029 insertions, 0 deletions
diff --git a/src/lxml/isoschematron/__init__.py b/src/lxml/isoschematron/__init__.py
new file mode 100644
index 00000000..7ef56616
--- /dev/null
+++ b/src/lxml/isoschematron/__init__.py
@@ -0,0 +1,277 @@
+"""The ``lxml.isoschematron`` package implements ISO Schematron support on top
+of the pure-xslt 'skeleton' implementation.
+"""
+
+import os.path
+from lxml import etree as _etree # due to validator __init__ signature
+
+# some compat stuff, borrowed from lxml.html
+try:
+ bytes = __builtins__["bytes"]
+except (KeyError, NameError):
+ # Python < 2.6
+ bytes = str
+try:
+ unicode = __builtins__["unicode"]
+except (KeyError, NameError):
+ # Python 3
+ unicode = str
+try:
+ basestring = __builtins__["basestring"]
+except (KeyError, NameError):
+ # Python 3
+ basestring = str
+
+
+# some namespaces
+#FIXME: Maybe lxml should provide a dedicated place for common namespace
+#FIXME: definitions?
+XML_SCHEMA_NS = "http://www.w3.org/2001/XMLSchema"
+RELAXNG_NS = "http://relaxng.org/ns/structure/1.0"
+SCHEMATRON_NS = "http://purl.oclc.org/dsdl/schematron"
+SVRL_NS = "http://purl.oclc.org/dsdl/svrl"
+
+
+# some helpers
+_schematron_root = '{%s}schema' % SCHEMATRON_NS
+_xml_schema_root = '{%s}schema' % XML_SCHEMA_NS
+_resources_dir = os.path.join(os.path.dirname(__file__), 'resources')
+
+
+# the iso-schematron skeleton implementation steps aka xsl transformations
+extract_from_xsd = _etree.XSLT(_etree.parse(
+ os.path.join(_resources_dir, 'xsl', 'XSD2Schtrn.xsl')))
+extract_from_rng = _etree.XSLT(_etree.parse(
+ os.path.join(_resources_dir, 'xsl', 'RNG2Schtrn.xsl')))
+iso_dsdl_include = _etree.XSLT(_etree.parse(
+ os.path.join(_resources_dir, 'xsl', 'iso-schematron-xslt1',
+ 'iso_dsdl_include.xsl')))
+iso_abstract_expand = _etree.XSLT(_etree.parse(
+ os.path.join(_resources_dir, 'xsl', 'iso-schematron-xslt1',
+ 'iso_abstract_expand.xsl')))
+iso_svrl_for_xslt1 = _etree.XSLT(_etree.parse(
+ os.path.join(_resources_dir,
+ 'xsl', 'iso-schematron-xslt1', 'iso_svrl_for_xslt1.xsl')))
+# if you want to use another "meta-stylesheet" for compilation to xslt, plug it
+# here
+iso_compile2xslt = iso_svrl_for_xslt1
+
+
+# svrl result accessors
+svrl_validation_errors = _etree.XPath(
+ '//svrl:failed-assert', namespaces={'svrl': SVRL_NS})
+
+
+# RelaxNG validator for schematron schemas
+schematron_schema_valid = _etree.RelaxNG(_etree.parse(
+ os.path.join(_resources_dir, 'rng', 'iso-schematron.rng')))
+
+
+def stylesheet_params(**kwargs):
+ """Convert keyword args to a dictionary of stylesheet parameters.
+ Conversion follows these rules:
+ If an arg is a string wrap it with XSLT.strparam().
+ If an arg is an XPath object use its path string.
+ If arg is None ignore the parameter.
+ Else convert arg to string.
+ """
+ result = {}
+ for key, val in kwargs.items():
+ if isinstance(val, basestring):
+ val = _etree.XSLT.strparam(val)
+ elif val is None:
+ continue
+ elif not isinstance(val, _etree.XPath):
+ val = unicode(val)
+ result[key] = val
+ return result
+
+
+# helper function for use in Schematron __init__
+def _stylesheet_param_dict(paramsDict, kwargsDict):
+ """Return a copy of paramsDict, updated with kwargsDict entries, wrapped as
+ stylesheet arguments.
+ kwargsDict entries with a value of None are ignored.
+ """
+ if paramsDict:
+ # beware of changing mutable default arg
+ paramsDict = dict(paramsDict)
+ for k, v in kwargsDict.items():
+ if v is not None: # None values do not override
+ paramsDict[k] = v
+ else:
+ paramsDict = kwargsDict
+ paramsDict = stylesheet_params(**paramsDict)
+ return paramsDict
+
+
+class Schematron(_etree._Validator):
+ """An ISO Schematron validator.
+
+ Pass a root Element or an ElementTree to turn it into a validator.
+ Alternatively, pass a filename as keyword argument 'file' to parse from
+ the file system.
+ Built on the Schematron language 'reference' skeleton pure-xslt
+ implementation, the validator is created as an XSLT 1.0 stylesheet using
+ these steps:
+ 0) (Extract from XML Schema or RelaxNG schema)
+ 1) Process inclusions
+ 2) Process abstract patterns
+ 3) Compile the schematron schema to XSLT
+ The ``include`` and ``expand`` keyword arguments can be used to switch off
+ steps 1) and 2).
+ To set parameters for steps 1), 2) and 3) hand dictionaries containing xslt
+ parameters to the keyword arguments ``include_params``, ``expand_params``
+ or ``compile_params``.
+ If ``store_schematron`` is set to True, the (included-and-expanded)
+ schematron document tree is stored and available through the ``schematron``
+ property.
+ If ``store_xslt`` is set to True, the validation XSLT document tree will be
+ stored and can be retrieved through the ``validator_xslt`` property.
+ With ``store_report`` set to True (default: False), the resulting validation
+ report document gets stored and can be accessed as the ``validation_report``
+ property.
+
+ Schematron is a less well known, but very powerful schema language. The main
+ idea is to use the capabilities of XPath to put restrictions on the structure
+ and the content of XML documents. Here is a simple example::
+
+ >>> from lxml import isoschematron
+ >>> schematron = isoschematron.Schematron(etree.XML('''
+ ... <schema xmlns="http://purl.oclc.org/dsdl/schematron" >
+ ... <pattern id="id_only_attribute">
+ ... <title>id is the only permitted attribute name</title>
+ ... <rule context="*">
+ ... <report test="@*[not(name()='id')]">Attribute
+ ... <name path="@*[not(name()='id')]"/> is forbidden<name/>
+ ... </report>
+ ... </rule>
+ ... </pattern>
+ ... </schema>
+ ... '''))
+
+ >>> xml = etree.XML('''
+ ... <AAA name="aaa">
+ ... <BBB id="bbb"/>
+ ... <CCC color="ccc"/>
+ ... </AAA>
+ ... ''')
+
+ >>> schematron.validate(xml)
+ 0
+
+ >>> xml = etree.XML('''
+ ... <AAA id="aaa">
+ ... <BBB id="bbb"/>
+ ... <CCC/>
+ ... </AAA>
+ ... ''')
+
+ >>> schematron.validate(xml)
+ 1
+ """
+
+ _domain = _etree.ErrorDomains.SCHEMATRONV
+ _level = _etree.ErrorLevels.ERROR
+ _error_type = _etree.ErrorTypes.SCHEMATRONV_ASSERT
+
+ def __init__(self, etree=None, file=None, include=True, expand=True,
+ include_params={}, expand_params={}, compile_params={},
+ store_schematron=False, store_xslt=False, store_report=False,
+ phase=None):
+ super(self.__class__, self).__init__()
+
+ self._store_report = store_report
+ self._schematron = None
+ self._validator_xslt = None
+ self._validation_report = None
+
+ # parse schema document, may be a schematron schema or an XML Schema or
+ # a RelaxNG schema with embedded schematron rules
+ try:
+ if etree is not None:
+ if isinstance(etree, _etree._Element):
+ root = etree
+ else:
+ root = etree.getroot()
+ elif file is not None:
+ root = _etree.parse(file).getroot()
+ except Exception, e:
+ raise _etree.SchematronParseError(
+ "No tree or file given: %s" % e)
+ if root is None:
+ raise ValueError("Empty tree")
+ if root.tag == _schematron_root:
+ schematron = root
+ elif root.tag == _xml_schema_root:
+ schematron = extract_from_xsd(root)
+ elif root.nsmap[root.prefix] == RELAXNG_NS:
+ # RelaxNG does not have a single unique root element
+ schematron = extract_from_rng(root)
+ else:
+ raise _etree.SchematronParseError(
+ "Document is not a schematron schema or schematron-extractable")
+ # perform the iso-schematron skeleton implementation steps to get a
+ # validating xslt
+ if include:
+ schematron = iso_dsdl_include(schematron, **include_params)
+ if expand:
+ schematron = iso_abstract_expand(schematron, **expand_params)
+ if not schematron_schema_valid(schematron):
+ raise _etree.SchematronParseError(
+ "invalid schematron schema: %s" %
+ schematron_schema_valid.error_log)
+ if store_schematron:
+ self._schematron = schematron
+ # add new compile keyword args here if exposing them
+ compile_kwargs = {'phase': phase}
+ compile_params = _stylesheet_param_dict(compile_params, compile_kwargs)
+ validator_xslt = iso_compile2xslt(schematron, **compile_params)
+ if store_xslt:
+ self._validator_xslt = validator_xslt
+ self._validator = _etree.XSLT(validator_xslt)
+
+ def __call__(self, etree):
+ """Validate doc using Schematron.
+
+ Returns true if document is valid, false if not.
+ """
+ self._clear_error_log()
+ result = self._validator(etree)
+ if self._store_report:
+ self._validation_report = result
+ errors = svrl_validation_errors(result)
+ if errors:
+ if isinstance(etree, _etree._Element):
+ fname = etree.getroottree().docinfo.URL or '<file>'
+ else:
+ fname = etree.docinfo.URL or '<file>'
+ for error in errors:
+ # Does svrl report the line number, anywhere? Don't think so.
+ self._append_log_message(
+ domain=self._domain, type=self._error_type,
+ level=self._level, line=0, message=_etree.tounicode(error),
+ filename=fname)
+ return False
+ return True
+
+ def schematron(self):
+ """ISO-schematron schema document (None if object has been initialized
+ with store_schematron=False).
+ """
+ return self._schematron
+ schematron = property(schematron, doc=schematron.__doc__)
+
+ def validator_xslt(self):
+ """ISO-schematron skeleton implementation XSLT validator document (None
+ if object has been initialized with store_xslt=False).
+ """
+ return self._validator_xslt
+ validator_xslt = property(validator_xslt, doc=validator_xslt.__doc__)
+
+ def validation_report(self):
+ """ISO-schematron validation result report (None if result-storing has
+ been turned off).
+ """
+ return self._validation_report
+ validation_report = property(validation_report, doc=validation_report.__doc__)
diff --git a/src/lxml/isoschematron/resources/rng/iso-schematron.rng b/src/lxml/isoschematron/resources/rng/iso-schematron.rng
new file mode 100644
index 00000000..d822f0d6
--- /dev/null
+++ b/src/lxml/isoschematron/resources/rng/iso-schematron.rng
@@ -0,0 +1,622 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ (c) International Organization for Standardization 2005.
+ Permission to copy in any form is granted for use with conforming
+ SGML systems and applications as defined in ISO 8879,
+ provided this notice is included in all copies.
+-->
+<grammar ns="http://purl.oclc.org/dsdl/schematron" xmlns="http://relaxng.org/ns/structure/1.0" datatypeLibrary="http://www.w3.org/2001/XMLSchema-datatypes">
+ <start>
+ <ref name="schema"/>
+ </start>
+ <!-- Element declarations -->
+ <define name="schema">
+ <element name="schema">
+ <optional>
+ <attribute name="id">
+ <data type="ID"/>
+ </attribute>
+ </optional>
+ <ref name="rich"/>
+ <optional>
+ <attribute name="schemaVersion">
+ <ref name="non-empty-string"/>
+ </attribute>
+ </optional>
+ <optional>
+ <attribute name="defaultPhase">
+ <data type="IDREF"/>
+ </attribute>
+ </optional>
+ <optional>
+ <attribute name="queryBinding">
+ <ref name="non-empty-string"/>
+ </attribute>
+ </optional>
+ <interleave>
+ <ref name="foreign"/>
+ <zeroOrMore>
+ <ref name="inclusion"/>
+ </zeroOrMore>
+ <group>
+ <optional>
+ <ref name="title"/>
+ </optional>
+ <zeroOrMore>
+ <ref name="ns"/>
+ </zeroOrMore>
+ <zeroOrMore>
+ <ref name="p"/>
+ </zeroOrMore>
+ <zeroOrMore>
+ <ref name="let"/>
+ </zeroOrMore>
+ <zeroOrMore>
+ <ref name="phase"/>
+ </zeroOrMore>
+ <oneOrMore>
+ <ref name="pattern"/>
+ </oneOrMore>
+ <zeroOrMore>
+ <ref name="p"/>
+ </zeroOrMore>
+ <optional>
+ <ref name="diagnostics"/>
+ </optional>
+ </group>
+ </interleave>
+ </element>
+ </define>
+ <define name="active">
+ <element name="active">
+ <attribute name="pattern">
+ <data type="IDREF"/>
+ </attribute>
+ <interleave>
+ <ref name="foreign"/>
+ <zeroOrMore>
+ <choice>
+ <text/>
+ <ref name="dir"/>
+ <ref name="emph"/>
+ <ref name="span"/>
+ </choice>
+ </zeroOrMore>
+ </interleave>
+ </element>
+ </define>
+ <define name="assert">
+ <element name="assert">
+ <attribute name="test">
+ <ref name="exprValue"/>
+ </attribute>
+ <optional>
+ <attribute name="flag">
+ <ref name="flagValue"/>
+ </attribute>
+ </optional>
+ <optional>
+ <attribute name="id">
+ <data type="ID"/>
+ </attribute>
+ </optional>
+ <optional>
+ <attribute name="diagnostics">
+ <data type="IDREFS"/>
+ </attribute>
+ </optional>
+ <ref name="rich"/>
+ <ref name="linkable"/>
+ <interleave>
+ <ref name="foreign"/>
+ <zeroOrMore>
+ <choice>
+ <text/>
+ <ref name="name"/>
+ <ref name="value-of"/>
+ <ref name="emph"/>
+ <ref name="dir"/>
+ <ref name="span"/>
+ </choice>
+ </zeroOrMore>
+ </interleave>
+ </element>
+ </define>
+ <define name="diagnostic">
+ <element name="diagnostic">
+ <attribute name="id">
+ <data type="ID"/>
+ </attribute>
+ <ref name="rich"/>
+ <interleave>
+ <ref name="foreign"/>
+ <zeroOrMore>
+ <choice>
+ <text/>
+ <ref name="value-of"/>
+ <ref name="emph"/>
+ <ref name="dir"/>
+ <ref name="span"/>
+ </choice>
+ </zeroOrMore>
+ </interleave>
+ </element>
+ </define>
+ <define name="diagnostics">
+ <element name="diagnostics">
+ <interleave>
+ <ref name="foreign"/>
+ <zeroOrMore>
+ <ref name="inclusion"/>
+ </zeroOrMore>
+ <zeroOrMore>
+ <ref name="diagnostic"/>
+ </zeroOrMore>
+ </interleave>
+ </element>
+ </define>
+ <define name="dir">
+ <element name="dir">
+ <optional>
+ <attribute name="value">
+ <choice>
+ <value>ltr</value>
+ <value>rtl</value>
+ </choice>
+ </attribute>
+ </optional>
+ <interleave>
+ <ref name="foreign"/>
+ <text/>
+ </interleave>
+ </element>
+ </define>
+ <define name="emph">
+ <element name="emph">
+ <text/>
+ </element>
+ </define>
+ <define name="extends">
+ <element name="extends">
+ <attribute name="rule">
+ <data type="IDREF"/>
+ </attribute>
+ <ref name="foreign-empty"/>
+ </element>
+ </define>
+ <define name="let">
+ <element name="let">
+ <attribute name="name">
+ <ref name="nameValue"/>
+ </attribute>
+ <attribute name="value">
+ <data type="string" datatypeLibrary=""/>
+ </attribute>
+ </element>
+ </define>
+ <define name="name">
+ <element name="name">
+ <optional>
+ <attribute name="path">
+ <ref name="pathValue"/>
+ </attribute>
+ </optional>
+ <ref name="foreign-empty"/>
+ </element>
+ </define>
+ <define name="ns">
+ <element name="ns">
+ <attribute name="uri">
+ <ref name="uriValue"/>
+ </attribute>
+ <attribute name="prefix">
+ <ref name="nameValue"/>
+ </attribute>
+ <ref name="foreign-empty"/>
+ </element>
+ </define>
+ <define name="p">
+ <element name="p">
+ <optional>
+ <attribute name="id">
+ <data type="ID"/>
+ </attribute>
+ </optional>
+ <optional>
+ <attribute name="class">
+ <ref name="classValue"/>
+ </attribute>
+ </optional>
+ <optional>
+ <attribute name="icon">
+ <ref name="uriValue"/>
+ </attribute>
+ </optional>
+ <interleave>
+ <ref name="foreign"/>
+ <zeroOrMore>
+ <choice>
+ <text/>
+ <ref name="dir"/>
+ <ref name="emph"/>
+ <ref name="span"/>
+ </choice>
+ </zeroOrMore>
+ </interleave>
+ </element>
+ </define>
+ <define name="param">
+ <element name="param">
+ <attribute name="name">
+ <ref name="nameValue"/>
+ </attribute>
+ <attribute name="value">
+ <ref name="non-empty-string"/>
+ </attribute>
+ </element>
+ </define>
+ <define name="pattern">
+ <element name="pattern">
+ <ref name="rich"/>
+ <interleave>
+ <ref name="foreign"/>
+ <zeroOrMore>
+ <ref name="inclusion"/>
+ </zeroOrMore>
+ <choice>
+ <group>
+ <attribute name="abstract">
+ <value>true</value>
+ </attribute>
+ <attribute name="id">
+ <data type="ID"/>
+ </attribute>
+ <optional>
+ <ref name="title"/>
+ </optional>
+ <group>
+ <zeroOrMore>
+ <ref name="p"/>
+ </zeroOrMore>
+ <zeroOrMore>
+ <ref name="let"/>
+ </zeroOrMore>
+ <zeroOrMore>
+ <ref name="rule"/>
+ </zeroOrMore>
+ </group>
+ </group>
+ <group>
+ <optional>
+ <attribute name="abstract">
+ <value>false</value>
+ </attribute>
+ </optional>
+ <optional>
+ <attribute name="id">
+ <data type="ID"/>
+ </attribute>
+ </optional>
+ <optional>
+ <ref name="title"/>
+ </optional>
+ <group>
+ <zeroOrMore>
+ <ref name="p"/>
+ </zeroOrMore>
+ <zeroOrMore>
+ <ref name="let"/>
+ </zeroOrMore>
+ <zeroOrMore>
+ <ref name="rule"/>
+ </zeroOrMore>
+ </group>
+ </group>
+ <group>
+ <optional>
+ <attribute name="abstract">
+ <value>false</value>
+ </attribute>
+ </optional>
+ <attribute name="is-a">
+ <data type="IDREF"/>
+ </attribute>
+ <optional>
+ <attribute name="id">
+ <data type="ID"/>
+ </attribute>
+ </optional>
+ <optional>
+ <ref name="title"/>
+ </optional>
+ <group>
+ <zeroOrMore>
+ <ref name="p"/>
+ </zeroOrMore>
+ <zeroOrMore>
+ <ref name="param"/>
+ </zeroOrMore>
+ </group>
+ </group>
+ </choice>
+ </interleave>
+ </element>
+ </define>
+ <define name="phase">
+ <element name="phase">
+ <attribute name="id">
+ <data type="ID"/>
+ </attribute>
+ <ref name="rich"/>
+ <interleave>
+ <ref name="foreign"/>
+ <zeroOrMore>
+ <ref name="inclusion"/>
+ </zeroOrMore>
+ <group>
+ <zeroOrMore>
+ <ref name="p"/>
+ </zeroOrMore>
+ <zeroOrMore>
+ <ref name="let"/>
+ </zeroOrMore>
+ <zeroOrMore>
+ <ref name="active"/>
+ </zeroOrMore>
+ </group>
+ </interleave>
+ </element>
+ </define>
+ <define name="report">
+ <element name="report">
+ <attribute name="test">
+ <ref name="exprValue"/>
+ </attribute>
+ <optional>
+ <attribute name="flag">
+ <ref name="flagValue"/>
+ </attribute>
+ </optional>
+ <optional>
+ <attribute name="id">
+ <data type="ID"/>
+ </attribute>
+ </optional>
+ <optional>
+ <attribute name="diagnostics">
+ <data type="IDREFS"/>
+ </attribute>
+ </optional>
+ <ref name="rich"/>
+ <ref name="linkable"/>
+ <interleave>
+ <ref name="foreign"/>
+ <zeroOrMore>
+ <choice>
+ <text/>
+ <ref name="name"/>
+ <ref name="value-of"/>
+ <ref name="emph"/>
+ <ref name="dir"/>
+ <ref name="span"/>
+ </choice>
+ </zeroOrMore>
+ </interleave>
+ </element>
+ </define>
+ <define name="rule">
+ <element name="rule">
+ <optional>
+ <attribute name="flag">
+ <ref name="flagValue"/>
+ </attribute>
+ </optional>
+ <ref name="rich"/>
+ <ref name="linkable"/>
+ <interleave>
+ <ref name="foreign"/>
+ <zeroOrMore>
+ <ref name="inclusion"/>
+ </zeroOrMore>
+ <choice>
+ <group>
+ <attribute name="abstract">
+ <value>true</value>
+ </attribute>
+ <attribute name="id">
+ <data type="ID"/>
+ </attribute>
+ <zeroOrMore>
+ <ref name="let"/>
+ </zeroOrMore>
+ <oneOrMore>
+ <choice>
+ <ref name="assert"/>
+ <ref name="report"/>
+ <ref name="extends"/>
+ </choice>
+ </oneOrMore>
+ </group>
+ <group>
+ <attribute name="context">
+ <ref name="pathValue"/>
+ </attribute>
+ <optional>
+ <attribute name="id">
+ <data type="ID"/>
+ </attribute>
+ </optional>
+ <optional>
+ <attribute name="abstract">
+ <value>false</value>
+ </attribute>
+ </optional>
+ <zeroOrMore>
+ <ref name="let"/>
+ </zeroOrMore>
+ <oneOrMore>
+ <choice>
+ <ref name="assert"/>
+ <ref name="report"/>
+ <ref name="extends"/>
+ </choice>
+ </oneOrMore>
+ </group>
+ </choice>
+ </interleave>
+ </element>
+ </define>
+ <define name="span">
+ <element name="span">
+ <attribute name="class">
+ <ref name="classValue"/>
+ </attribute>
+ <interleave>
+ <ref name="foreign"/>
+ <text/>
+ </interleave>
+ </element>
+ </define>
+ <define name="title">
+ <element name="title">
+ <zeroOrMore>
+ <choice>
+ <text/>
+ <ref name="dir"/>
+ </choice>
+ </zeroOrMore>
+ </element>
+ </define>
+ <define name="value-of">
+ <element name="value-of">
+ <attribute name="select">
+ <ref name="pathValue"/>
+ </attribute>
+ <ref name="foreign-empty"/>
+ </element>
+ </define>
+ <!-- common declarations -->
+ <define name="inclusion">
+ <element name="include">
+ <attribute name="href">
+ <ref name="uriValue"/>
+ </attribute>
+ </element>
+ </define>
+ <define name="rich">
+ <optional>
+ <attribute name="icon">
+ <ref name="uriValue"/>
+ </attribute>
+ </optional>
+ <optional>
+ <attribute name="see">
+ <ref name="uriValue"/>
+ </attribute>
+ </optional>
+ <optional>
+ <attribute name="fpi">
+ <ref name="fpiValue"/>
+ </attribute>
+ </optional>
+ <optional>
+ <attribute name="xml:lang">
+ <ref name="langValue"/>
+ </attribute>
+ </optional>
+ <optional>
+ <attribute name="xml:space">
+ <choice>
+ <value>preserve</value>
+ <value>default</value>
+ </choice>
+ </attribute>
+ </optional>
+ </define>
+ <define name="linkable">
+ <optional>
+ <attribute name="role">
+ <ref name="roleValue"/>
+ </attribute>
+ </optional>
+ <optional>
+ <attribute name="subject">
+ <ref name="pathValue"/>
+ </attribute>
+ </optional>
+ </define>
+ <define name="foreign">
+ <ref name="foreign-attributes"/>
+ <zeroOrMore>
+ <ref name="foreign-element"/>
+ </zeroOrMore>
+ </define>
+ <define name="foreign-empty">
+ <ref name="foreign-attributes"/>
+ </define>
+ <define name="foreign-attributes">
+ <zeroOrMore>
+ <attribute>
+ <anyName>
+ <except>
+ <nsName ns=""/>
+ <nsName ns="http://www.w3.org/XML/1998/namespace"/>
+ </except>
+ </anyName>
+ </attribute>
+ </zeroOrMore>
+ </define>
+ <define name="foreign-element">
+ <element>
+ <anyName>
+ <except>
+ <nsName/>
+ </except>
+ </anyName>
+ <zeroOrMore>
+ <choice>
+ <attribute>
+ <anyName/>
+ </attribute>
+ <ref name="foreign-element"/>
+ <ref name="schema"/>
+ <text/>
+ </choice>
+ </zeroOrMore>
+ </element>
+ </define>
+ <!-- Data types -->
+ <define name="uriValue">
+ <data type="anyURI"/>
+ </define>
+ <define name="pathValue">
+ <data type="string" datatypeLibrary=""/>
+ </define>
+ <define name="exprValue">
+ <data type="string" datatypeLibrary=""/>
+ </define>
+ <define name="fpiValue">
+ <data type="string" datatypeLibrary=""/>
+ </define>
+ <define name="langValue">
+ <data type="language"/>
+ </define>
+ <define name="roleValue">
+ <data type="string" datatypeLibrary=""/>
+ </define>
+ <define name="flagValue">
+ <data type="string" datatypeLibrary=""/>
+ </define>
+ <define name="nameValue">
+ <data type="string" datatypeLibrary=""/>
+ </define>
+ <!-- In the default query language binding, xsd:NCNAME -->
+ <define name="classValue">
+ <data type="string" datatypeLibrary=""/>
+ </define>
+ <define name="non-empty-string">
+ <data type="token">
+ <param name="minLength">1</param>
+ </data>
+ </define>
+</grammar>
diff --git a/src/lxml/isoschematron/resources/xsl/RNG2Schtrn.xsl b/src/lxml/isoschematron/resources/xsl/RNG2Schtrn.xsl
new file mode 100644
index 00000000..21a5d2a0
--- /dev/null
+++ b/src/lxml/isoschematron/resources/xsl/RNG2Schtrn.xsl
@@ -0,0 +1,75 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Stylesheet for extracting Schematron information from a RELAX-NG schema.
+ Based on the stylesheet for extracting Schematron information from W3C XML Schema.
+ Created by Eddie Robertsson 2002/06/01
+ 2009/12/10 hj: changed Schematron namespace to ISO URI (Holger Joukl)
+-->
+<xsl:transform version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
+xmlns:sch="http://purl.oclc.org/dsdl/schematron" xmlns:rng="http://relaxng.org/ns/structure/1.0">
+ <!-- Set the output to be XML with an XML declaration and use indentation -->
+ <xsl:output method="xml" omit-xml-declaration="no" indent="yes" standalone="yes"/>
+ <!-- -->
+ <!-- match schema and call recursive template to extract included schemas -->
+ <!-- -->
+ <xsl:template match="/rng:grammar | /rng:element">
+ <!-- call the schema definition template ... -->
+ <xsl:call-template name="gatherSchema">
+ <!-- ... with current node as the $schemas parameter ... -->
+ <xsl:with-param name="schemas" select="."/>
+ <!-- ... and any includes in the $include parameter -->
+ <xsl:with-param name="includes" select="document(/rng:grammar/rng:include/@href
+| //rng:externalRef/@href)"/>
+ </xsl:call-template>
+ </xsl:template>
+ <!-- -->
+ <!-- gather all included schemas into a single parameter variable -->
+ <!-- -->
+ <xsl:template name="gatherSchema">
+ <xsl:param name="schemas"/>
+ <xsl:param name="includes"/>
+ <xsl:choose>
+ <xsl:when test="count($schemas) &lt; count($schemas | $includes)">
+ <!-- when $includes includes something new, recurse ... -->
+ <xsl:call-template name="gatherSchema">
+ <!-- ... with current $includes added to the $schemas parameter ... -->
+ <xsl:with-param name="schemas" select="$schemas | $includes"/>
+ <!-- ... and any *new* includes in the $include parameter -->
+ <xsl:with-param name="includes" select="document($includes/rng:grammar/rng:include/@href
+| $includes//rng:externalRef/@href)"/>
+ </xsl:call-template>
+ </xsl:when>
+ <xsl:otherwise>
+ <!-- we have the complete set of included schemas, so now let's output the embedded schematron -->
+ <xsl:call-template name="output">
+ <xsl:with-param name="schemas" select="$schemas"/>
+ </xsl:call-template>
+ </xsl:otherwise>
+ </xsl:choose>
+ </xsl:template>
+ <!-- -->
+ <!-- output the schematron information -->
+ <!-- -->
+ <xsl:template name="output">
+ <xsl:param name="schemas"/>
+ <!-- -->
+ <sch:schema>
+ <!-- get header-type elements - eg title and especially ns -->
+ <!-- title (just one) -->
+ <xsl:copy-of select="$schemas//sch:title[1]"/>
+ <!-- get remaining schematron schema children -->
+ <!-- get non-blank namespace elements, dropping duplicates -->
+ <xsl:for-each select="$schemas//sch:ns">
+ <xsl:if test="generate-id(.) = generate-id($schemas//sch:ns[@prefix = current()/@prefix][1])">
+ <xsl:copy-of select="."/>
+ </xsl:if>
+ </xsl:for-each>
+ <xsl:copy-of select="$schemas//sch:phase"/>
+ <xsl:copy-of select="$schemas//sch:pattern"/>
+ <sch:diagnostics>
+ <xsl:copy-of select="$schemas//sch:diagnostics/*"/>
+ </sch:diagnostics>
+ </sch:schema>
+ </xsl:template>
+ <!-- -->
+</xsl:transform>
diff --git a/src/lxml/isoschematron/resources/xsl/XSD2Schtrn.xsl b/src/lxml/isoschematron/resources/xsl/XSD2Schtrn.xsl
new file mode 100644
index 00000000..de0c9ea7
--- /dev/null
+++ b/src/lxml/isoschematron/resources/xsl/XSD2Schtrn.xsl
@@ -0,0 +1,77 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ based on an original transform by Eddie Robertsson
+ 2001/04/21 fn: added support for included schemas
+ 2001/06/27 er: changed XMl Schema prefix from xsd: to xs: and changed to the Rec namespace
+ 2009/12/10 hj: changed Schematron namespace to ISO URI (Holger Joukl)
+-->
+<xsl:transform version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
+xmlns:sch="http://purl.oclc.org/dsdl/schematron" xmlns:xs="http://www.w3.org/2001/XMLSchema">
+ <!-- Set the output to be XML with an XML declaration and use indentation -->
+ <xsl:output method="xml" omit-xml-declaration="no" indent="yes" standalone="yes"/>
+ <!-- -->
+ <!-- match schema and call recursive template to extract included schemas -->
+ <!-- -->
+ <xsl:template match="xs:schema">
+ <!-- call the schema definition template ... -->
+ <xsl:call-template name="gatherSchema">
+ <!-- ... with current current root as the $schemas parameter ... -->
+ <xsl:with-param name="schemas" select="/"/>
+ <!-- ... and any includes in the $include parameter -->
+ <xsl:with-param name="includes"
+ select="document(/xs:schema/xs:*[self::xs:include or self::xs:import or self::xs:redefine]/@schemaLocation)"/>
+ </xsl:call-template>
+ </xsl:template>
+ <!-- -->
+ <!-- gather all included schemas into a single parameter variable -->
+ <!-- -->
+ <xsl:template name="gatherSchema">
+ <xsl:param name="schemas"/>
+ <xsl:param name="includes"/>
+ <xsl:choose>
+ <xsl:when test="count($schemas) &lt; count($schemas | $includes)">
+ <!-- when $includes includes something new, recurse ... -->
+ <xsl:call-template name="gatherSchema">
+ <!-- ... with current $includes added to the $schemas parameter ... -->
+ <xsl:with-param name="schemas" select="$schemas | $includes"/>
+ <!-- ... and any *new* includes in the $include parameter -->
+ <xsl:with-param name="includes"
+ select="document($includes/xs:schema/xs:*[self::xs:include or self::xs:import or self::xs:redefine]/@schemaLocation)"/>
+ </xsl:call-template>
+ </xsl:when>
+ <xsl:otherwise>
+ <!-- we have the complete set of included schemas,
+ so now let's output the embedded schematron -->
+ <xsl:call-template name="output">
+ <xsl:with-param name="schemas" select="$schemas"/>
+ </xsl:call-template>
+ </xsl:otherwise>
+ </xsl:choose>
+ </xsl:template>
+ <!-- -->
+ <!-- output the schematron information -->
+ <!-- -->
+ <xsl:template name="output">
+ <xsl:param name="schemas"/>
+ <!-- -->
+ <sch:schema>
+ <!-- get header-type elements - eg title and especially ns -->
+ <!-- title (just one) -->
+ <xsl:copy-of select="$schemas//xs:appinfo/sch:title[1]"/>
+ <!-- get remaining schematron schema children -->
+ <!-- get non-blank namespace elements, dropping duplicates -->
+ <xsl:for-each select="$schemas//xs:appinfo/sch:ns">
+ <xsl:if test="generate-id(.) =
+ generate-id($schemas//xs:appinfo/sch:ns[@prefix = current()/@prefix][1])">
+ <xsl:copy-of select="."/>
+ </xsl:if>
+ </xsl:for-each>
+ <xsl:copy-of select="$schemas//xs:appinfo/sch:phase"/>
+ <xsl:copy-of select="$schemas//xs:appinfo/sch:pattern"/>
+ <sch:diagnostics>
+ <xsl:copy-of select="$schemas//xs:appinfo/sch:diagnostics/*"/>
+ </sch:diagnostics>
+ </sch:schema>
+ </xsl:template>
+ <!-- -->
+</xsl:transform>
diff --git a/src/lxml/isoschematron/resources/xsl/iso-schematron-xslt1/iso_abstract_expand.xsl b/src/lxml/isoschematron/resources/xsl/iso-schematron-xslt1/iso_abstract_expand.xsl
new file mode 100644
index 00000000..057c7c1f
--- /dev/null
+++ b/src/lxml/isoschematron/resources/xsl/iso-schematron-xslt1/iso_abstract_expand.xsl
@@ -0,0 +1,296 @@
+<?xml version="1.0" encoding="UTF-8"?><?xar XSLT?>
+
+<!--
+ OVERVIEW - iso_abstract_expand.xsl
+
+ This is a preprocessor for ISO Schematron, which implements abstract patterns.
+ It also
+ * extracts a particular schema using an ID, where there are multiple
+ schemas, such as when they are embedded in the same NVDL script
+ * experimentally, allows parameter recognition and substitution inside
+ text as well as @context, @test, & @select.
+
+
+ This should be used after iso-dsdl-include.xsl and before the skeleton or
+ meta-stylesheet (e.g. iso-svrl.xsl) . It only requires XSLT 1.
+
+ Each kind of inclusion can be turned off (or on) on the command line.
+
+-->
+<!--
+ VERSION INFORMATION
+ 2008-09-18 RJ
+ * move out param test from iso:schema template to work with XSLT 1. (Noah Fontes)
+
+ 2008-07-29 RJ
+ * Create. Pull out as distinct XSL in its own namespace from old iso_pre_pro.xsl
+ * Put everything in private namespace
+ * Rewrite replace_substring named template so that copyright is clear
+
+ 2008-07-24 RJ
+ * correct abstract patterns so for correct names: param/@name and
+ param/@value
+
+ 2007-01-12 RJ
+ * Use ISO namespace
+ * Use pattern/@id not pattern/@name
+ * Add Oliver Becker's suggests from old Schematron-love-in list for <copy>
+ * Add XT -ism?
+ 2003 RJ
+ * Original written for old namespace
+ * http://www.topologi.com/resources/iso-pre-pro.xsl
+-->
+<!--
+ LEGAL INFORMATION
+
+ Copyright (c) 2000-2008 Rick Jelliffe and Academia Sinica Computing Center, Taiwan
+
+ This software is provided 'as-is', without any express or implied warranty.
+ In no event will the authors be held liable for any damages arising from
+ the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it freely,
+ subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not claim
+ that you wrote the original software. If you use this software in a product,
+ an acknowledgment in the product documentation would be appreciated but is
+ not required.
+
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+
+ 3. This notice may not be removed or altered from any source distribution.
+-->
+<xslt:stylesheet version="1.0" xmlns:xslt="http://www.w3.org/1999/XSL/Transform"
+ xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
+ xmlns:iso="http://purl.oclc.org/dsdl/schematron"
+ xmlns:nvdl="http://purl.oclc.org/dsdl/nvdl"
+
+
+ xmlns:iae="http://www.schematron.com/namespace/iae"
+
+ >
+
+ <xslt:param name="schema-id"></xslt:param>
+
+
+ <!-- Driver for the mode -->
+ <xsl:template match="/">
+ <xsl:apply-templates select="." mode="iae:go" />
+ </xsl:template>
+
+
+ <!-- ================================================================================== -->
+ <!-- Normal processing rules -->
+ <!-- ================================================================================== -->
+ <!-- Output only the selected schema -->
+ <xslt:template match="iso:schema" >
+ <xsl:if test="string-length($schema-id) =0 or @id= $schema-id ">
+ <xslt:copy>
+ <xslt:copy-of select="@*" />
+ <xslt:apply-templates mode="iae:go" />
+ </xslt:copy>
+ </xsl:if>
+ </xslt:template>
+
+
+ <!-- Strip out any foreign elements above the Schematron schema .
+ -->
+ <xslt:template match="*[not(ancestor-or-self::iso:*)]" mode="iae:go" >
+ <xslt:apply-templates mode="iae:go" />
+ </xslt:template>
+
+
+ <!-- ================================================================================== -->
+ <!-- Handle Schematron abstract pattern preprocessing -->
+ <!-- abstract-to-real calls
+ do-pattern calls
+ macro-expand calls
+ multi-macro-expand
+ replace-substring -->
+ <!-- ================================================================================== -->
+
+ <!--
+ Abstract patterns allow you to say, for example
+
+ <pattern name="htmlTable" is-a="table">
+ <param name="row" value="html:tr"/>
+ <param name="cell" value="html:td" />
+ <param name="table" value="html:table" />
+ </pattern>
+
+ For a good introduction, see Uche Ogbujii's article for IBM DeveloperWorks
+ "Discover the flexibility of Schematron abstract patterns"
+ http://www-128.ibm.com/developerworks/xml/library/x-stron.html
+ However, note that ISO Schematron uses @name and @value attributes on
+ the iso:param element, and @id not @name on the pattern element.
+
+ -->
+
+ <!-- Suppress declarations of abstract patterns -->
+ <xslt:template match="iso:pattern[@abstract='true']" mode="iae:go" >
+ <xslt:comment>Suppressed abstract pattern <xslt:value-of select="@id"/> was here</xslt:comment>
+ </xslt:template>
+
+
+ <!-- Suppress uses of abstract patterns -->
+ <xslt:template match="iso:pattern[@is-a]" mode="iae:go" >
+
+ <xslt:comment>Start pattern based on abstract <xslt:value-of select="@is-a"/></xslt:comment>
+
+ <xslt:call-template name="iae:abstract-to-real" >
+ <xslt:with-param name="caller" select="@id" />
+ <xslt:with-param name="is-a" select="@is-a" />
+ </xslt:call-template>
+
+ </xslt:template>
+
+
+
+ <!-- output everything else unchanged -->
+ <xslt:template match="*" priority="-1" mode="iae:go" >
+ <xslt:copy>
+ <xslt:copy-of select="@*" />
+ <xslt:apply-templates mode="iae:go"/>
+ </xslt:copy>
+ </xslt:template>
+
+ <!-- Templates for macro expansion of abstract patterns -->
+ <!-- Sets up the initial conditions for the recursive call -->
+ <xslt:template name="iae:macro-expand">
+ <xslt:param name="caller"/>
+ <xslt:param name="text" />
+ <xslt:call-template name="iae:multi-macro-expand">
+ <xslt:with-param name="caller" select="$caller"/>
+ <xslt:with-param name="text" select="$text"/>
+ <xslt:with-param name="paramNumber" select="1"/>
+ </xslt:call-template>
+
+ </xslt:template>
+
+ <!-- Template to replace the current parameter and then
+ recurse to replace subsequent parameters. -->
+
+ <xslt:template name="iae:multi-macro-expand">
+ <xslt:param name="caller"/>
+ <xslt:param name="text" />
+ <xslt:param name="paramNumber" />
+
+
+ <xslt:choose>
+ <xslt:when test="//iso:pattern[@id=$caller]/iso:param[ $paramNumber]">
+
+ <xslt:call-template name="iae:multi-macro-expand">
+ <xslt:with-param name="caller" select="$caller"/>
+ <xslt:with-param name="paramNumber" select="$paramNumber + 1"/>
+ <xslt:with-param name="text" >
+ <xslt:call-template name="iae:replace-substring">
+ <xslt:with-param name="original" select="$text"/>
+ <xslt:with-param name="substring"
+ select="concat('$', //iso:pattern[@id=$caller]/iso:param[ $paramNumber ]/@name)"/>
+ <xslt:with-param name="replacement"
+ select="//iso:pattern[@id=$caller]/iso:param[ $paramNumber ]/@value"/>
+ </xslt:call-template>
+ </xslt:with-param>
+ </xslt:call-template>
+ </xslt:when>
+ <xslt:otherwise><xslt:value-of select="$text" /></xslt:otherwise>
+
+ </xslt:choose>
+ </xslt:template>
+
+
+ <!-- generate the real pattern from an abstract pattern + parameters-->
+ <xslt:template name="iae:abstract-to-real" >
+ <xslt:param name="caller"/>
+ <xslt:param name="is-a" />
+ <xslt:for-each select="//iso:pattern[@id= $is-a]">
+ <xslt:copy>
+
+ <xslt:choose>
+ <xslt:when test=" string-length( $caller ) = 0">
+ <xslt:attribute name="id"><xslt:value-of select="concat( generate-id(.) , $is-a)" /></xslt:attribute>
+ </xslt:when>
+ <xslt:otherwise>
+ <xslt:attribute name="id"><xslt:value-of select="$caller" /></xslt:attribute>
+ </xslt:otherwise>
+ </xslt:choose>
+
+ <xslt:apply-templates select="*|text()" mode="iae:do-pattern" >
+ <xslt:with-param name="caller"><xslt:value-of select="$caller"/></xslt:with-param>
+ </xslt:apply-templates>
+
+ </xslt:copy>
+ </xslt:for-each>
+ </xslt:template>
+
+
+ <!-- Generate a non-abstract pattern -->
+ <xslt:template mode="iae:do-pattern" match="*">
+ <xslt:param name="caller"/>
+ <xslt:copy>
+ <xslt:for-each select="@*[name()='test' or name()='context' or name()='select']">
+ <xslt:attribute name="{name()}">
+ <xslt:call-template name="iae:macro-expand">
+ <xslt:with-param name="text"><xslt:value-of select="."/></xslt:with-param>
+ <xslt:with-param name="caller"><xslt:value-of select="$caller"/></xslt:with-param>
+ </xslt:call-template>
+ </xslt:attribute>
+ </xslt:for-each>
+ <xslt:copy-of select="@*[name()!='test'][name()!='context'][name()!='select']" />
+ <xsl:for-each select="node()">
+ <xsl:choose>
+ <!-- Experiment: replace macros in text as well, to allow parameterized assertions
+ and so on, without having to have spurious <iso:value-of> calls and multiple
+ delimiting -->
+ <xsl:when test="self::text()">
+ <xslt:call-template name="iae:macro-expand">
+ <xslt:with-param name="text"><xslt:value-of select="."/></xslt:with-param>
+ <xslt:with-param name="caller"><xslt:value-of select="$caller"/></xslt:with-param>
+ </xslt:call-template>
+ </xsl:when>
+ <xsl:otherwise>
+ <xslt:apply-templates select="." mode="iae:do-pattern">
+ <xslt:with-param name="caller"><xslt:value-of select="$caller"/></xslt:with-param>
+ </xslt:apply-templates>
+ </xsl:otherwise>
+ </xsl:choose>
+ </xsl:for-each>
+ </xslt:copy>
+ </xslt:template>
+
+ <!-- UTILITIES -->
+ <!-- Simple version of replace-substring function -->
+ <xslt:template name="iae:replace-substring">
+ <xslt:param name="original" />
+ <xslt:param name="substring" />
+ <xslt:param name="replacement" select="''"/>
+
+ <xsl:choose>
+ <xsl:when test="not($original)" />
+ <xsl:when test="not(string($substring))">
+ <xsl:value-of select="$original" />
+ </xsl:when>
+ <xsl:when test="contains($original, $substring)">
+ <xsl:variable name="before" select="substring-before($original, $substring)" />
+ <xsl:variable name="after" select="substring-after($original, $substring)" />
+
+ <xsl:value-of select="$before" />
+ <xsl:value-of select="$replacement" />
+ <!-- recursion -->
+ <xsl:call-template name="iae:replace-substring">
+ <xsl:with-param name="original" select="$after" />
+ <xsl:with-param name="substring" select="$substring" />
+ <xsl:with-param name="replacement" select="$replacement" />
+ </xsl:call-template>
+ </xsl:when>
+ <xsl:otherwise>
+ <!-- no substitution -->
+ <xsl:value-of select="$original" />
+ </xsl:otherwise>
+ </xsl:choose>
+</xslt:template>
+
+</xslt:stylesheet> \ No newline at end of file
diff --git a/src/lxml/isoschematron/resources/xsl/iso-schematron-xslt1/iso_dsdl_include.xsl b/src/lxml/isoschematron/resources/xsl/iso-schematron-xslt1/iso_dsdl_include.xsl
new file mode 100644
index 00000000..44e5573b
--- /dev/null
+++ b/src/lxml/isoschematron/resources/xsl/iso-schematron-xslt1/iso_dsdl_include.xsl
@@ -0,0 +1,1160 @@
+<?xml version="1.0" encoding="UTF-8"?><?xar XSLT?>
+
+<!--
+ OVERVIEW : iso_dsdl_include.xsl
+
+ This is an inclusion preprocessor for the non-smart text inclusions
+ of ISO DSDL. It handles
+ <relax:extRef> for ISO RELAX NG
+ <sch:include> for ISO Schematron and Schematron 1.n
+ <sch:extends> for 2009 draft ISO Schematron
+ <xi:xinclude> simple W3C XIncludes for ISO NVRL and DSRL
+ <crdl:ref> for draft ISO CRDL
+ <dtll:include> for draft ISO DTLL
+ <* @xlink:href> for simple W3C XLink 1.1 embedded links
+
+
+ This should be the first in any chain of processing. It only requires
+ XSLT 1. Each kind of inclusion can be turned off (or on) on the command line.
+
+ Ids in fragment identifiers or xpointers will be sought in the following
+ order:
+ * @xml:id
+ * id() for typed schemas (e.g. from DTD) [NOTE: XInclude does not support this]
+ * untyped @id
+
+ The proposed behaviour for the update to ISO Schematron has been implemented. If an
+ include points to an element with the same name as the parent, then that element's
+ contents will be included. This supports the merge style of inclusion.
+
+ When an inclusion is made, it is preceded by a PI with target DSDL_INCLUDE_START
+ and the href and closed by a PI with target DSDL_INCLUDE_START and the href. This is
+ to allow better location of problems, though only to the file level.
+
+ Limitations:
+ * No rebasing: relative paths will be interpreted based on the initial document's
+ path, not the including document. (Severe limitation!)
+ * No checking for circular references
+ * Not full xpointers: only ID matching
+ * <relax:include> not implemented
+ * XInclude handling of xml:base and xml:lang not implemented
+-->
+<!--
+ VERSION INFORMATION
+ 2009-02-25
+ * Update DSDL namespace to use schematron.com
+ * Tested with SAXON9, Xalan 2.7.1, IE7,
+ * IE does not like multiple variables in same template with same name: rename.
+ 2008-09-18
+ * Remove new behaviour for include, because it conflicts with existing usage [KH]
+ * Add extends[@href] element with that merge functionality
+ * Generate PIs to notate source of inclusions for potential better diagnostics
+
+ 2008-09-16
+ * Fix for XSLT1
+
+ 2008-08-28
+ * New behaviour for schematron includes: if the pointed to element is the same as the current,
+ include the children.
+
+ 2008-08-20
+ * Fix bug: in XSLT1 cannot do $document/id('x') but need to use for-each
+
+ 2008-08-04
+ * Add support for inclusions in old namespace
+
+ 2008-08-03
+ * Fix wrong param name include-relaxng & include-crdl (KH, PH)
+ * Allow inclusion of XSLT and XHTML (KH)
+ * Fix inclusion of fragments (KH)
+
+ 2008-07-25
+ * Add selectable input parameter
+
+ 2008-07-24
+ * RJ New
+-->
+<!--
+ LEGAL INFORMATION
+
+ Copyright (c) 2008 Rick Jelliffe
+
+ This software is provided 'as-is', without any express or implied warranty.
+ In no event will the authors be held liable for any damages arising from
+ the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it freely,
+ subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not claim
+ that you wrote the original software. If you use this software in a product,
+ an acknowledgment in the product documentation would be appreciated but is
+ not required.
+
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+
+ 3. This notice may not be removed or altered from any source distribution.
+-->
+<xslt:stylesheet version="1.0"
+ xmlns:xslt="http://www.w3.org/1999/XSL/Transform"
+ xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
+ xmlns:iso="http://purl.oclc.org/dsdl/schematron"
+ xmlns:nvdl="http://purl.oclc.org/dsdl/nvdl"
+ xmlns:xhtml="http://www.w3.org/1999/xhtml"
+ xmlns:schold="http://www.ascc.net/xml/schematron"
+ xmlns:crdl="http://purl.oclc.org/dsdl/crepdl/ns/structure/1.0"
+ xmlns:xi="http://www.w3.org/2001/XInclude"
+ xmlns:dtll="http://www.jenitennison.com/datatypes"
+ xmlns:dsdl="http://www.schematron.com/namespace/dsdl"
+ xmlns:relax="http://relaxng.org/ns/structure/1.0"
+ xmlns:xlink="http://www.w3.org/1999/xlink">
+ <!-- Note: The URL for the dsdl namespace is not official -->
+
+
+ <xsl:param name="include-schematron">true</xsl:param>
+ <xsl:param name="include-crdl">true</xsl:param>
+ <xsl:param name="include-xinclude">true</xsl:param>
+ <xsl:param name="include-dtll">true</xsl:param>
+ <xsl:param name="include-relaxng">true</xsl:param>
+ <xsl:param name="include-xlink">true</xsl:param>
+
+ <xsl:template match="/">
+ <xsl:apply-templates select="." mode="dsdl:go" />
+ </xsl:template>
+
+ <!-- output everything else unchanged -->
+ <xslt:template match="node()" priority="-1" mode="dsdl:go">
+ <xslt:copy>
+ <xslt:copy-of select="@*" />
+ <xslt:apply-templates mode="dsdl:go" />
+ </xslt:copy>
+ </xslt:template>
+
+
+
+ <!-- =========================================================== -->
+ <!-- ISO/IEC 19757 - DSDL Document Schema Definition Languages -->
+ <!-- Part 2 - Regular grammar-based validation - RELAX NG -->
+ <!-- This only implements relax:extRef not relax:include which -->
+ <!-- is complex. -->
+ <!-- =========================================================== -->
+ <xslt:template match="relax:extRef" mode="dsdl:go">
+
+
+ <!-- Insert subschema -->
+
+ <xsl:variable name="document-uri"
+ select="substring-before(concat(@href,'#'), '#')" />
+ <xsl:variable name="fragment-id"
+ select="substring-after(@href, '#')" />
+
+ <xsl:processing-instruction name="DSDL_INCLUDE_START">
+ <xsl:value-of select="@href" />
+ </xsl:processing-instruction>
+ <xsl:choose>
+ <xsl:when test="not( $include-relaxng = 'true' )">
+ <xslt:copy>
+ <xslt:copy-of select="@*" />
+ <xslt:apply-templates mode="dsdl:go" />
+ </xslt:copy>
+ </xsl:when>
+ <xsl:otherwise>
+
+ <xsl:choose>
+
+ <xsl:when
+ test="string-length( $document-uri ) = 0 and string-length( $fragment-id ) = 0">
+ <xsl:message>
+ Error: Impossible URL in RELAX NG extRef
+ include
+ </xsl:message>
+ </xsl:when>
+
+ <!-- this case is when there is in embedded schema in the same document elsewhere -->
+ <xslt:when
+ test="string-length( $document-uri ) = 0">
+ <xslt:apply-templates mode="dsdl:go"
+ select="//*[@xml:id= $fragment-id ] | id( $fragment-id) | //*[@id= $fragment-id ]" />
+ </xslt:when>
+
+ <xsl:when
+ test="string-length( $fragment-id ) &gt; 0">
+ <xsl:variable name="theDocument_1"
+ select="document( $document-uri,/ )" />
+
+ <xsl:if test="not($theDocument_1)">
+ <xsl:message terminate="no">
+ <xsl:text>Unable to open referenced included file: </xsl:text>
+ <xsl:value-of select="@href" />
+ </xsl:message>
+ </xsl:if>
+ <!-- use a for-each so that the id() function works correctly on the external document -->
+ <xsl:for-each select="$theDocument_1">
+ <xsl:variable name="theFragment_1"
+ select="$theDocument_1//*[@xml:id= $fragment-id ]
+ | id( $fragment-id)
+ | $theDocument_1//*[@id= $fragment-id ]" />
+ <xsl:if test="not($theFragment_1)">
+ <xsl:message terminate="no">
+ <xsl:text>Unable to locate id attribute: </xsl:text>
+ <xsl:value-of select="@href" />
+ </xsl:message>
+ </xsl:if>
+ <xsl:apply-templates
+ select=" $theFragment_1[1]" mode="dsdl:go" />
+ </xsl:for-each>
+ </xsl:when>
+
+ <xsl:otherwise>
+ <xsl:variable name="theDocument_2"
+ select="document( $document-uri,/ )" />
+ <xsl:variable name="theFragment_2"
+ select="$theDocument_2/*" />
+ <xsl:if test="not($theDocument_2)">
+ <xsl:message terminate="no">
+ <xsl:text>Unable to open referenced included file: </xsl:text>
+ <xsl:value-of select="@href" />
+ </xsl:message>
+ </xsl:if>
+
+ <xsl:if test="not($theFragment_2)">
+ <xsl:message terminate="no">
+ <xsl:text>Unable to locate id attribute: </xsl:text>
+ <xsl:value-of select="@href" />
+ </xsl:message>
+ </xsl:if>
+ <xsl:apply-templates select="$theFragment_2 "
+ mode="dsdl:go" />
+ </xsl:otherwise>
+ </xsl:choose>
+
+ </xsl:otherwise>
+ </xsl:choose>
+
+ <xsl:processing-instruction name="DSDL_INCLUDE_END">
+ <xsl:value-of select="@href" />
+ </xsl:processing-instruction>
+ </xslt:template>
+
+
+
+ <!-- =========================================================== -->
+ <!-- ISO/IEC 19757 - DSDL Document Schema Definition Languages -->
+ <!-- Part 3 - Rule-based validation - Schematron -->
+ <!-- =========================================================== -->
+
+
+ <!-- Extend the URI syntax to allow # references -->
+ <!-- Add experimental support for simple containers like /xxx:xxx/iso:pattern to allow better includes -->
+ <xsl:template match="iso:include" mode="dsdl:go">
+
+ <xsl:variable name="document-uri"
+ select="substring-before(concat(@href,'#'), '#')" />
+ <xsl:variable name="fragment-id"
+ select="substring-after(@href, '#')" />
+
+
+ <xsl:processing-instruction name="DSDL_INCLUDE_START">
+ <xsl:value-of select="@href" />
+ </xsl:processing-instruction>
+
+ <xsl:choose>
+ <xsl:when test="not( $include-schematron = 'true' )">
+ <xslt:copy>
+ <xslt:copy-of select="@*" />
+ <xslt:apply-templates mode="dsdl:go" />
+ </xslt:copy>
+ </xsl:when>
+ <xsl:otherwise>
+
+ <xsl:choose>
+
+ <xsl:when
+ test="string-length( $document-uri ) = 0 and string-length( $fragment-id ) = 0">
+ <xsl:message>
+ Error: Impossible URL in Schematron include
+ </xsl:message>
+ </xsl:when>
+
+ <!-- this case is when there is in embedded schema in the same document elsewhere -->
+ <xslt:when
+ test="string-length( $document-uri ) = 0">
+ <xslt:apply-templates mode="dsdl:go"
+ select="//iso:*[@xml:id= $fragment-id ]
+ |id( $fragment-id)
+ | //iso:*[@id= $fragment-id ]" />
+ </xslt:when>
+
+ <!-- case where there is a fragment in another document (should be an iso: element) -->
+ <!-- There are three cases for includes with fragment:
+ 0) No href file or no matching id - error!
+ 1) REMOVED
+
+ 2) The linked-to element is sch:schema however the parent of the include
+ is not a schema. In this case, it is an error. (Actually, it should
+ be an error for other kinds of containment problems, but we won't
+ check for them in this version.)
+
+ 3) Otherwise, include the pointed-to element
+ -->
+
+ <xsl:when
+ test="string-length( $fragment-id ) &gt; 0">
+ <xsl:variable name="theDocument_1"
+ select="document( $document-uri,/ )" />
+ <xsl:variable name="originalParent" select=".." />
+
+ <!-- case 0 -->
+ <xsl:if test="not($theDocument_1)">
+ <xsl:message terminate="no">
+ <xsl:text>Unable to open referenced included file: </xsl:text>
+ <xsl:value-of select="@href" />
+ </xsl:message>
+ </xsl:if>
+ <!-- use for-each to rebase id() to external document -->
+ <xsl:for-each select="$theDocument_1">
+ <xsl:variable name="theFragment_1"
+ select=" $theDocument_1//iso:*[@xml:id= $fragment-id ] |
+ id($fragment-id) |
+ $theDocument_1//iso:*[@id= $fragment-id ]" />
+
+
+ <xsl:choose>
+ <!-- case 0 -->
+ <xsl:when test="not($theFragment_1)">
+ <xsl:message terminate="no">
+ <xsl:text>Unable to locate id attribute: </xsl:text>
+ <xsl:value-of select="@href" />
+ </xsl:message>
+ </xsl:when>
+
+
+ <!-- case 1 REMOVED -->
+
+ <!-- case 2 -->
+ <xsl:when
+ test=" $theFragment_1/self::iso:schema ">
+ <xsl:message>
+ Schema error: Use include to
+ include fragments, not a whole
+ schema
+ </xsl:message>
+ </xsl:when>
+
+ <!-- case 3 -->
+ <xsl:otherwise>
+ <xsl:apply-templates
+ select=" $theFragment_1[1]" mode="dsdl:go" />
+ </xsl:otherwise>
+ </xsl:choose>
+ </xsl:for-each>
+ </xsl:when>
+
+ <!-- Case where there is no ID so we include the whole document -->
+ <!-- Experimental addition: include fragments of children -->
+ <xsl:otherwise>
+ <xsl:variable name="theDocument_2"
+ select="document( $document-uri,/ )" />
+ <xsl:variable name="theFragment_2"
+ select="$theDocument_2/iso:*" />
+ <xsl:variable name="theContainedFragments"
+ select="$theDocument_2/*/iso:* | $theDocument_2/*/xsl:* | $theDocument_2/*/xhtml:*" />
+ <xsl:if test="not($theDocument_2)">
+ <xsl:message terminate="no">
+ <xsl:text>Unable to open referenced included file: </xsl:text>
+ <xsl:value-of select="@href" />
+ </xsl:message>
+ </xsl:if>
+
+ <!-- There are three cases for includes:
+ 0) No text specified- error!
+
+ 1) REMOVED
+
+ 2) The linked-to element is sch:schema however the parent of the include
+ is not a schema. In this case, it is an error. (Actually, it should
+ be an error for other kinds of containment problems, but we won't
+ check for them in this version.)
+
+ 3) Otherwise, include the pointed-to element
+ -->
+ <xsl:choose>
+ <!-- case 0 -->
+ <xsl:when
+ test="not($theFragment_2) and not ($theContainedFragments)">
+ <xsl:message terminate="no">
+ <xsl:text>Unable to locate id attribute: </xsl:text>
+ <xsl:value-of select="@href" />
+ </xsl:message>
+ </xsl:when>
+
+ <!-- case 1 removed -->
+
+ <!-- case 2 -->
+ <xsl:when
+ test=" $theFragment_2/self::iso:schema or $theContainedFragments/self::iso:schema">
+ <xsl:message>
+ Schema error: Use include to include
+ fragments, not a whole schema
+ </xsl:message>
+ </xsl:when>
+
+ <!-- If this were XLST 2, we could use
+ if ($theFragment) then $theFragment else $theContainedFragments
+ here (thanks to KN)
+ -->
+ <!-- case 3 -->
+ <xsl:otherwise>
+ <xsl:apply-templates
+ select="$theFragment_2 " mode="dsdl:go" />
+ </xsl:otherwise>
+ </xsl:choose>
+ </xsl:otherwise>
+ </xsl:choose>
+ </xsl:otherwise>
+ </xsl:choose>
+
+ <xsl:processing-instruction name="DSDL_INCLUDE_END">
+ <xsl:value-of select="@href" />
+ </xsl:processing-instruction>
+ </xsl:template>
+
+
+ <!-- WARNING sch:extends[@href] is experimental and non standard -->
+ <!-- Basically, it adds the children of the selected element, not the element itself. -->
+ <xsl:template match="iso:extends[@href]" mode="dsdl:go">
+
+ <xsl:variable name="document-uri"
+ select="substring-before(concat(@href,'#'), '#')" />
+ <xsl:variable name="fragment-id"
+ select="substring-after(@href, '#')" />
+
+
+ <xsl:processing-instruction name="DSDL_INCLUDE_START">
+ <xsl:value-of select="@href" />
+ </xsl:processing-instruction>
+
+ <xsl:choose>
+ <xsl:when test="not( $include-schematron = 'true' )">
+ <xslt:copy>
+ <xslt:copy-of select="@*" />
+ <xslt:apply-templates mode="dsdl:go" />
+ </xslt:copy>
+ </xsl:when>
+ <xsl:otherwise>
+
+ <xsl:choose>
+
+ <xsl:when
+ test="string-length( $document-uri ) = 0 and string-length( $fragment-id ) = 0">
+ <xsl:message>
+ Error: Impossible URL in Schematron include
+ </xsl:message>
+ </xsl:when>
+
+ <!-- this case is when there is in embedded schema in the same document elsewhere -->
+ <xslt:when
+ test="string-length( $document-uri ) = 0">
+ <xslt:apply-templates mode="dsdl:go"
+ select="//iso:*[@xml:id= $fragment-id ]/*
+ |id( $fragment-id)/*
+ | //iso:*[@id= $fragment-id ]/*" />
+ </xslt:when>
+
+ <!-- case where there is a fragment in another document (should be an iso: element) -->
+ <!-- There are three cases for includes with fragment:
+ 0) No href file or no matching id - error!
+ 1) REMOVED
+
+ 2) REMOVED
+
+ 3) Otherwise, include the pointed-to element
+ -->
+
+ <xsl:when
+ test="string-length( $fragment-id ) &gt; 0">
+ <xsl:variable name="theDocument_1"
+ select="document( $document-uri,/ )" />
+ <xsl:variable name="originalParent" select=".." />
+
+ <!-- case 0 -->
+ <xsl:if test="not($theDocument_1)">
+ <xsl:message terminate="no">
+ <xsl:text>Unable to open referenced included file: </xsl:text>
+ <xsl:value-of select="@href" />
+ </xsl:message>
+ </xsl:if>
+ <!-- use for-each to rebase id() to external document -->
+ <xsl:for-each select="$theDocument_1">
+ <xsl:variable name="theFragment_1"
+ select=" $theDocument_1//iso:*[@xml:id= $fragment-id ] |
+ id($fragment-id) |
+ $theDocument_1//iso:*[@id= $fragment-id ]" />
+
+
+ <xsl:choose>
+ <!-- case 0 -->
+ <xsl:when test="not($theFragment_1)">
+ <xsl:message terminate="no">
+ <xsl:text>Unable to locate id attribute: </xsl:text>
+ <xsl:value-of select="@href" />
+ </xsl:message>
+ </xsl:when>
+
+
+ <!-- case 1 REMOVED -->
+
+ <!-- case 2 REMOVED -->
+
+
+ <!-- case 3 -->
+ <xsl:otherwise>
+
+ <xsl:apply-templates
+ select=" $theFragment_1[1]/*" mode="dsdl:go" />
+ </xsl:otherwise>
+ </xsl:choose>
+ </xsl:for-each>
+ </xsl:when>
+
+ <!-- Case where there is no ID so we include the whole document -->
+ <!-- Experimental addition: include fragments of children -->
+ <xsl:otherwise>
+ <xsl:variable name="theDocument_2"
+ select="document( $document-uri,/ )" />
+ <xsl:variable name="theFragment_2"
+ select="$theDocument_2/iso:*" />
+ <xsl:variable name="theContainedFragments"
+ select="$theDocument_2/*/iso:* | $theDocument_2/*/xsl:* | $theDocument_2/*/xhtml:*" />
+ <xsl:if test="not($theDocument_2)">
+ <xsl:message terminate="no">
+ <xsl:text>Unable to open referenced included file: </xsl:text>
+ <xsl:value-of select="@href" />
+ </xsl:message>
+ </xsl:if>
+
+ <!-- There are three cases for includes:
+ 0) No text specified- error!
+
+ 1) REMOVED
+
+ 2) REMOVED
+
+ 3) Otherwise, include the pointed-to element
+ -->
+ <xsl:choose>
+ <!-- case 0 -->
+ <xsl:when
+ test="not($theFragment_2) and not ($theContainedFragments)">
+ <xsl:message terminate="no">
+ <xsl:text>Unable to locate id attribute: </xsl:text>
+ <xsl:value-of select="@href" />
+ </xsl:message>
+ </xsl:when>
+
+ <!-- case 1 removed -->
+
+ <!-- case 2 removed -->
+
+ <!-- If this were XLST 2, we could use
+ if ($theFragment) then $theFragment else $theContainedFragments
+ here (thanks to KN)
+ -->
+ <!-- case 3 -->
+ <xsl:otherwise>
+ <xsl:apply-templates
+ select="$theFragment_2/* " mode="dsdl:go" />
+ </xsl:otherwise>
+ </xsl:choose>
+ </xsl:otherwise>
+ </xsl:choose>
+ </xsl:otherwise>
+ </xsl:choose>
+
+ <xsl:processing-instruction name="DSDL_INCLUDE_END">
+ <xsl:value-of select="@href" />
+ </xsl:processing-instruction>
+ </xsl:template>
+
+
+
+ <!-- =========================================================== -->
+ <!-- Handle Schematron 1.6 inclusions: clone of ISO code above -->
+ <!-- =========================================================== -->
+
+
+ <!-- Extend the URI syntax to allow # references -->
+ <!-- Add experimental support for simple containers like /xxx:xxx/schold:pattern to allow better includes -->
+ <xsl:template match="schold:include" mode="dsdl:go">
+ <xsl:variable name="document-uri"
+ select="substring-before(concat(@href,'#'), '#')" />
+ <xsl:variable name="fragment-id"
+ select="substring-after(@href, '#')" />
+
+ <xsl:processing-instruction name="DSDL_INCLUDE_START">
+ <xsl:value-of select="@href" />
+ </xsl:processing-instruction>
+
+ <xsl:choose>
+ <xsl:when test="not( $include-schematron = 'true' )">
+ <xslt:copy>
+ <xslt:copy-of select="@*" />
+ <xslt:apply-templates mode="dsdl:go" />
+ </xslt:copy>
+ </xsl:when>
+ <xsl:otherwise>
+ <xsl:choose>
+
+ <xsl:when
+ test="string-length( $document-uri ) = 0 and string-length( $fragment-id ) = 0">
+ <xsl:message>
+ Error: Impossible URL in Schematron include
+ </xsl:message>
+ </xsl:when>
+
+ <!-- this case is when there is in embedded schema in the same document elsewhere -->
+ <xslt:when
+ test="string-length( $document-uri ) = 0">
+ <xslt:apply-templates mode="dsdl:go"
+ select="//schold:*[@xml:id= $fragment-id ]
+ |id( $fragment-id)
+ | //schold:*[@id= $fragment-id ]" />
+ </xslt:when>
+
+ <!-- case where there is a fragment in another document (should be an iso: element) -->
+ <xsl:when
+ test="string-length( $fragment-id ) &gt; 0">
+ <xsl:variable name="theDocument_1"
+ select="document( $document-uri,/ )" />
+ <xsl:if test="not($theDocument_1)">
+ <xsl:message terminate="no">
+ <xsl:text>Unable to open referenced included file: </xsl:text>
+ <xsl:value-of select="@href" />
+ </xsl:message>
+ </xsl:if>
+ <!-- use for-each to rebase id() to $theDocument -->
+ <xsl:for-each select="$theDocument_1">
+ <xsl:variable name="theFragment_1"
+ select=" $theDocument_1//schold:*[@xml:id= $fragment-id ] |
+ id($fragment-id) |
+ $theDocument_1//schold:*[@id= $fragment-id ]" />
+ <xsl:if
+ test=" $theFragment_1/self::schold:schema ">
+ <xsl:message>
+ Schema error: Use include to include
+ fragments, not a whole schema
+ </xsl:message>
+ </xsl:if>
+ <xsl:if test="not($theFragment_1)">
+ <xsl:message terminate="no">
+ <xsl:text>Unable to locate id attribute: </xsl:text>
+ <xsl:value-of select="@href" />
+ </xsl:message>
+ </xsl:if>
+ <xsl:apply-templates
+ select=" $theFragment_1[1]" mode="dsdl:go" />
+ </xsl:for-each>
+ </xsl:when>
+
+ <!-- Case where there is no ID so we include the whole document -->
+ <!-- Experimental addition: include fragments of children -->
+ <xsl:otherwise>
+ <xsl:variable name="theDocument_2"
+ select="document( $document-uri,/ )" />
+ <xsl:variable name="theFragment_2"
+ select="$theDocument_2/iso:*" />
+ <xsl:variable name="theContainedFragments"
+ select="$theDocument_2/*/schold:* | $theDocument_2/*/xsl:* | $theDocument_2/*/xhtml:*" />
+ <xsl:if test="not($theDocument_2)">
+ <xsl:message terminate="no">
+ <xsl:text>Unable to open referenced included file: </xsl:text>
+ <xsl:value-of select="@href" />
+ </xsl:message>
+ </xsl:if>
+
+ <xsl:if
+ test=" $theFragment_2/self::schold:schema or $theContainedFragments/self::schold:schema">
+ <xsl:message>
+ Schema error: Use include to include
+ fragments, not a whole schema
+ </xsl:message>
+ </xsl:if>
+ <xsl:if
+ test="not($theFragment_2) and not ($theContainedFragments)">
+ <xsl:message terminate="no">
+ <xsl:text>Unable to locate id attribute: </xsl:text>
+ <xsl:value-of select="@href" />
+ </xsl:message>
+ </xsl:if>
+ <!-- If this were XLST 2, we could use
+ if ($theFragment) then $theFragment else $theContainedFragments
+ here (thanks to KN)
+ -->
+ <xsl:choose>
+ <xsl:when test=" $theFragment_2 ">
+ <xsl:apply-templates
+ select="$theFragment_2 " mode="dsdl:go" />
+ </xsl:when>
+ <xsl:otherwise>
+ <!-- WARNING! EXPERIMENTAL! Use at your own risk. This may be discontinued! -->
+ <xsl:apply-templates
+ select=" $theContainedFragments " mode="dsdl:go" />
+ </xsl:otherwise>
+ </xsl:choose>
+ </xsl:otherwise>
+ </xsl:choose>
+
+ </xsl:otherwise>
+ </xsl:choose>
+
+ <xsl:processing-instruction name="DSDL_INCLUDE_END">
+ <xsl:value-of select="@href" />
+ </xsl:processing-instruction>
+ </xsl:template>
+ <!-- =========================================================== -->
+ <!-- ISO/IEC 19757 - DSDL Document Schema Definition Languages -->
+ <!-- Part 5 - DataType Library Language - DTLL -->
+ <!-- Committee Draft Experimental support only -->
+ <!-- The <include> element may well be replaced by XInclude in -->
+ <!-- any final version. -->
+ <!-- =========================================================== -->
+ <xslt:template match="dtll:include" mode="dsdl:go">
+ <!-- Insert subschema -->
+
+ <xsl:variable name="document-uri"
+ select="substring-before(concat(@href,'#'), '#')" />
+ <xsl:variable name="fragment-id"
+ select="substring-after(@href, '#')" />
+ <xsl:processing-instruction name="DSDL_INCLUDE_START">
+ <xsl:value-of select="@href" />
+ </xsl:processing-instruction>
+ <xsl:choose>
+ <xsl:when test="not( $include-dtll = 'true' )">
+ <xslt:copy>
+ <xslt:copy-of select="@*" />
+ <xslt:apply-templates mode="dsdl:go" />
+ </xslt:copy>
+ </xsl:when>
+ <xsl:otherwise>
+ <xsl:choose>
+
+ <xsl:when
+ test="string-length( $document-uri ) = 0 and string-length( $fragment-id ) = 0">
+ <xsl:message>
+ Error: Impossible URL in DTLL include
+ </xsl:message>
+ </xsl:when>
+
+ <!-- this case is when there is in embedded schema in the same document elsewhere -->
+ <xslt:when
+ test="string-length( $document-uri ) = 0">
+ <xslt:apply-templates mode="dsdl:go"
+ select="//*[@xml:id= $fragment-id ] | id( $fragment-id)
+ | //*[@id= $fragment-id ]" />
+ </xslt:when>
+
+ <xsl:when
+ test="string-length( $fragment-id ) &gt; 0">
+ <xsl:variable name="theDocument_1"
+ select="document( $document-uri,/ )" />
+ <xsl:if test="not($theDocument_1)">
+ <xsl:message terminate="no">
+ <xsl:text>Unable to open referenced included file: </xsl:text>
+ <xsl:value-of select="@href" />
+ </xsl:message>
+ </xsl:if>
+ <!-- use for-each to rebase id() to $theDocument -->
+ <xsl:for-each select="$theDocument_1">
+ <xsl:variable name="theFragment_1"
+ select="$theDocument_1//*[@xml:id= $fragment-id ]
+ | id( $fragment-id )
+ | $theDocument_1//*[@id= $fragment-id ]" />
+ <xsl:if test="not($theFragment_1)">
+ <xsl:message terminate="no">
+ <xsl:text>Unable to locate id attribute: </xsl:text>
+ <xsl:value-of select="@href" />
+ </xsl:message>
+ </xsl:if>
+ <xsl:apply-templates
+ select=" $theFragment_1[1]" mode="dsdl:go" />
+ </xsl:for-each>
+ </xsl:when>
+
+ <xsl:otherwise>
+ <xsl:variable name="theDocument_2"
+ select="document( $document-uri,/ )" />
+ <xsl:variable name="theFragment_2"
+ select="$theDocument_2/*" />
+
+ <xsl:if test="not($theDocument_2)">
+ <xsl:message terminate="no">
+ <xsl:text>Unable to open referenced included file: </xsl:text>
+ <xsl:value-of select="@href" />
+ </xsl:message>
+ </xsl:if>
+
+ <xsl:if test="not($theFragment_2)">
+ <xsl:message terminate="no">
+ <xsl:text>Unable to locate id attribute: </xsl:text>
+ <xsl:value-of select="@href" />
+ </xsl:message>
+ </xsl:if>
+ <xsl:apply-templates select="$theFragment_2 "
+ mode="dsdl:go" />
+ </xsl:otherwise>
+ </xsl:choose>
+
+ </xsl:otherwise>
+ </xsl:choose>
+ <xsl:processing-instruction name="DSDL_INCLUDE_END">
+ <xsl:value-of select="@href" />
+ </xsl:processing-instruction>
+ </xslt:template>
+
+ <!-- =========================================================== -->
+ <!-- ISO/IEC 19757 - DSDL Document Schema Definition Languages -->
+ <!-- Part 7 - Character Repertoire Description Language - CRDL -->
+ <!-- Final Committee Draft 2008-01-11 Experimental support only -->
+ <!-- =========================================================== -->
+ <xslt:template match="crdl:ref" mode="dsdl:go">
+ <!-- Insert subschema -->
+
+ <xsl:variable name="document-uri"
+ select="substring-before(concat(@href,'#'), '#')" />
+ <xsl:variable name="fragment-id"
+ select="substring-after(@href, '#')" />
+ <xsl:processing-instruction name="DSDL_INCLUDE_START">
+ <xsl:value-of select="@href" />
+ </xsl:processing-instruction>
+ <xsl:choose>
+ <xsl:when test="not( $include-crdl = 'true' )">
+ <xslt:copy>
+ <xslt:copy-of select="@*" />
+ <xslt:apply-templates mode="dsdl:go" />
+ </xslt:copy>
+ </xsl:when>
+ <xsl:otherwise>
+ <xsl:choose>
+
+ <xsl:when
+ test="string-length( $document-uri ) = 0 and string-length( $fragment-id ) = 0">
+ <xsl:message>
+ Error: Impossible URL in CRDL include
+ </xsl:message>
+ </xsl:when>
+
+ <!-- this case is when there is in embedded schema in the same document elsewhere -->
+ <xslt:when
+ test="string-length( $document-uri ) = 0">
+
+ <xslt:apply-templates mode="dsdl:go"
+ select="//*[@xml:id= $fragment-id ] | id( $fragment-id)
+ | //*[@id= $fragment-id ]" />
+ </xslt:when>
+
+ <xsl:when
+ test="string-length( $fragment-id ) &gt; 0">
+ <xsl:variable name="theDocument_1"
+ select="document( $document-uri,/ )" />
+ <xsl:if test="not($theDocument_1)">
+ <xsl:message terminate="no">
+ <xsl:text>Unable to open referenced included file: </xsl:text>
+ <xsl:value-of select="@href" />
+ </xsl:message>
+ </xsl:if>
+ <!-- use for-each to rebase id() to $theDocument -->
+ <xsl:for-each select="$theDocument_1">
+ <xsl:variable name="theFragment_1"
+ select="$theDocument_1//*[@xml:id= $fragment-id ]
+ | id( $fragment-id )
+ | $theDocument_1//*[@id= $fragment-id ]" />
+
+ <xsl:if test="not($theFragment_1)">
+ <xsl:message terminate="no">
+ <xsl:text>Unable to locate id attribute: </xsl:text>
+ <xsl:value-of select="@href" />
+ </xsl:message>
+ </xsl:if>
+ <xsl:apply-templates select=" $theFragment_1 "
+ mode="dsdl:go" />
+ </xsl:for-each>
+ </xsl:when>
+
+ <xsl:otherwise>
+ <xsl:variable name="theDocument_2"
+ select="document( $document-uri,/ )" />
+ <xsl:variable name="theFragment_2"
+ select="$theDocument_2/*" />
+
+ <xsl:if test="not($theDocument_2)">
+ <xsl:message terminate="no">
+ <xsl:text>Unable to open referenced included file: </xsl:text>
+ <xsl:value-of select="@href" />
+ </xsl:message>
+ </xsl:if>
+ <xsl:if test="not($theFragment_2)">
+ <xsl:message terminate="no">
+ <xsl:text>Unable to locate id attribute: </xsl:text>
+ <xsl:value-of select="@href" />
+ </xsl:message>
+ </xsl:if>
+
+ <xsl:apply-templates select="$theFragment_2"
+ mode="dsdl:go" />
+ </xsl:otherwise>
+ </xsl:choose>
+
+ </xsl:otherwise>
+ </xsl:choose>
+ <xsl:processing-instruction name="DSDL_INCLUDE_END">
+ <xsl:value-of select="@href" />
+ </xsl:processing-instruction>
+ </xslt:template>
+
+
+ <!-- =========================================================== -->
+ <!-- ISO/IEC 19757 - DSDL Document Schema Definition Languages -->
+ <!-- Part 4 - Namespace-based Validation Dispatching Language - NVDL -->
+ <!-- Note: This does not include schemas referenced for -->
+ <!-- validation, it merely handles any simple XIncludes -->
+ <!-- =========================================================== -->
+ <!-- ISO/IEC 19757 - DSDL Document Schema Definition Languages -->
+ <!-- Part 8 - Document Schema Renaming Language - DSRL -->
+ <!-- Note: Final? Committee Draft Experimental support only -->
+ <!-- =========================================================== -->
+ <!-- XInclude support for id based references only, with 1 level -->
+ <!-- of fallback. -->
+ <!-- =========================================================== -->
+
+ <xslt:template mode="dsdl:go"
+ match="xi:include[@href][not(@parseType) or @parseType ='xml']">
+ <!-- Simple inclusions only here -->
+ <xsl:processing-instruction name="DSDL_INCLUDE_START">
+ <xsl:value-of select="@href" />
+ </xsl:processing-instruction>
+ <xsl:choose>
+ <xsl:when test="not( $include-xinclude = 'true' )">
+ <xslt:copy>
+ <xslt:copy-of select="@*" />
+ <xslt:apply-templates mode="dsdl:go" />
+ </xslt:copy>
+ </xsl:when>
+ <xsl:otherwise>
+ <xsl:choose>
+
+ <xsl:when test="contains( @href, '#')">
+ <xsl:message terminate="yes">
+ Fatal error: Xinclude href contains fragment
+ identifier #
+ </xsl:message>
+ </xsl:when>
+
+
+ <xsl:when test="contains( @xpointer, '(')">
+ <xsl:message terminate="yes">
+ Fatal error: Sorry, this software only
+ supports simple ids in XInclude xpointers
+ </xsl:message>
+ </xsl:when>
+
+ <xsl:when
+ test="string-length( @href ) = 0 and string-length( @xpointer ) = 0">
+
+ <xsl:message terminate="yes">
+ Fatal Error: Impossible URL in XInclude
+ include
+ </xsl:message>
+ </xsl:when>
+
+ <!-- this case is when there is in embedded schema in the same document elsewhere -->
+ <xslt:when test="string-length( @href ) = 0">
+
+ <xslt:apply-templates mode="dsdl:go"
+ select="//*[@xml:id= current()/@xpointer ] | id( @xpointer)
+ | //*[@id= current()/@xpointer ]" />
+ </xslt:when>
+
+ <xsl:when
+ test="string-length( @xpointer ) &gt; 0">
+ <xsl:variable name="theDocument_1"
+ select="document( @href,/ )" />
+ <xsl:variable name="theFragment_1"
+ select="$theDocument_1//*[@xml:id= current()/@xpointer ]
+
+ | $theDocument_1//*[@id= current()/@xpointer ]" />
+ <!-- removed
+ | $theDocument_1/id( @xpointer)
+ because it requires rebasing in XSLT1 and that would mess up the use of current()
+ -->
+
+
+ <!-- Allow one level of fallback, to another XInclude -->
+ <xsl:if test="not($theDocument_1)">
+ <xsl:choose>
+ <xsl:when test="xi:fallback">
+ <xsl:variable name="theDocument_2"
+ select="document( xi:fallback[1]/xi:include[not(@parseType)
+ or @parseType='xml']/@href,/ )" />
+ <xsl:variable name="theFragment_2"
+ select="$theDocument_2//*[@xml:id= current()/xi:fallback[1]/xi:include/@xpointer ]
+ | $theDocument_2//*[@id= current()/xi:fallback[1]/xi:include/@xpointer ]" />
+ <!-- removed
+ | $theDocument_2/id( xi:fallback[1]/xi:include/@xpointer)
+ because it id() would need rebasing in XSLT1 and that would mess up use of current()
+ -->
+
+ <xsl:if
+ test="not($theDocument_2)">
+
+ <xsl:message terminate="no">
+ <xsl:text>Unable to open referenced included file and fallback
+ file: </xsl:text>
+ <xsl:value-of
+ select="@href" />
+ </xsl:message>
+ </xsl:if>
+ </xsl:when>
+ <xsl:otherwise>
+ <xsl:message terminate="no">
+ <xsl:text>Unable to open referenced included file: </xsl:text>
+ <xsl:value-of select="@href" />
+ </xsl:message>
+ </xsl:otherwise>
+ </xsl:choose>
+ </xsl:if>
+ <xsl:apply-templates select=" $theFragment_1"
+ mode="dsdl:go" />
+ </xsl:when>
+
+ <!-- Document but no fragment specified -->
+ <xsl:otherwise>
+ <xsl:variable name="theDocument_3"
+ select="document( @href,/ )" />
+ <xsl:variable name="theFragment_3"
+ select="$theDocument_3/*" />
+
+ <xsl:if test="not($theDocument_3)">
+ <xsl:message terminate="no">
+ <xsl:text>Unable to open referenced included file: </xsl:text>
+ <xsl:value-of select="@href" />
+ </xsl:message>
+ </xsl:if>
+
+ <xsl:apply-templates select="$theFragment_3 "
+ mode="dsdl:go" />
+ </xsl:otherwise>
+ </xsl:choose>
+
+ </xsl:otherwise>
+ </xsl:choose>
+ <xsl:processing-instruction name="DSDL_INCLUDE_END">
+ <xsl:value-of select="@href" />
+ </xsl:processing-instruction>
+ </xslt:template>
+
+ <!-- =========================================================== -->
+ <!-- W3C XLink 1.1 embedded simple links -->
+ <!-- =========================================================== -->
+ <xslt:template
+ match="*[@xlink:href][not(parent::*[@xlink:type='complex'])]
+ [not(@xlink:type) or (@xlink:type='simple')]
+ [@xlink:show='embed']
+ [not(@xlink:actuate) or (@xlink:actuate='onLoad')]"
+ mode="dsdl:go" priority="1">
+
+ <xsl:variable name="document-uri"
+ select="substring-before(concat(@xlink:href,'#'), '#')" />
+ <xsl:variable name="fragment-id"
+ select="substring-after(@xlink:href, '#')" />
+ <xsl:processing-instruction name="DSDL_INCLUDE_START">
+ <xsl:value-of select="@xlink:href" />
+ </xsl:processing-instruction>
+ <xsl:choose>
+ <xsl:when test="not( $include-xlink = 'true' )">
+ <xslt:copy>
+ <xslt:copy-of select="@*" />
+ <xslt:apply-templates mode="dsdl:go" />
+ </xslt:copy>
+ </xsl:when>
+ <xsl:otherwise>
+ <xsl:choose>
+
+ <xsl:when
+ test="string-length( $document-uri ) = 0 and string-length( $fragment-id ) = 0">
+ <xsl:message>
+ Error: Impossible URL in XLink embedding
+ link
+ </xsl:message>
+ </xsl:when>
+
+ <!-- this case is when there is in embedded schema in the same document elsewhere -->
+ <xslt:when
+ test="string-length( $document-uri ) = 0">
+ <xslt:apply-templates mode="dsdl:go"
+ select="//*[@xml:id= $fragment-id ] | id( $fragment-id)
+ | //*[@id= $fragment-id ]" />
+ </xslt:when>
+
+ <xsl:when
+ test="string-length( $fragment-id ) &gt; 0">
+ <xsl:variable name="theDocument_1"
+ select="document( $document-uri,/ )" />
+ <xsl:if test="not($theDocument_1)">
+ <xsl:message terminate="no">
+ <xsl:text>Unable to open referenced included file: </xsl:text>
+ <xsl:value-of select="@xlink:href" />
+ </xsl:message>
+ </xsl:if>
+ <!-- use for-each to rebase id() to $theDocument -->
+ <xsl:for-each select="$theDocument_1">
+ <xsl:variable name="theFragment_1"
+ select="$theDocument_1//*[@xml:id= $fragment-id ]
+ | id( $fragment-id )
+ | $theDocument_1//*[@id= $fragment-id ]" />
+ <xsl:if test="not($theFragment_1)">
+ <xsl:message terminate="no">
+ <xsl:text>Unable to locate id attribute: </xsl:text>
+ <xsl:value-of select="@xlink:href" />
+ </xsl:message>
+ </xsl:if>
+ <xsl:apply-templates
+ select=" $theFragment_1[1]" mode="dsdl:go" />
+ </xsl:for-each>
+ </xsl:when>
+
+ <xsl:otherwise>
+ <xsl:variable name="theDocument_2"
+ select="document( $document-uri,/ )" />
+ <xsl:variable name="theFragment_2"
+ select="$theDocument_2/*" />
+
+ <xsl:if test="not($theDocument_2)">
+ <xsl:message terminate="no">
+ <xsl:text>Unable to open referenced included file: </xsl:text>
+ <xsl:value-of select="@xlink:href" />
+ </xsl:message>
+ </xsl:if>
+
+ <xsl:if test="not($theFragment_2)">
+ <xsl:message terminate="no">
+ <xsl:text>Unable to locate id attribute: </xsl:text>
+ <xsl:value-of select="@xlink:href" />
+ </xsl:message>
+ </xsl:if>
+ <xsl:apply-templates select="$theFragment_2 "
+ mode="dsdl:go" />
+ </xsl:otherwise>
+ </xsl:choose>
+
+ </xsl:otherwise>
+ </xsl:choose>
+
+ <xsl:processing-instruction name="DSDL_INCLUDE_END">
+ <xsl:value-of select="@xlink:href" />
+ </xsl:processing-instruction>
+ </xslt:template>
+
+
+</xslt:stylesheet> \ No newline at end of file
diff --git a/src/lxml/isoschematron/resources/xsl/iso-schematron-xslt1/iso_schematron_message.xsl b/src/lxml/isoschematron/resources/xsl/iso-schematron-xslt1/iso_schematron_message.xsl
new file mode 100644
index 00000000..d59b8f38
--- /dev/null
+++ b/src/lxml/isoschematron/resources/xsl/iso-schematron-xslt1/iso_schematron_message.xsl
@@ -0,0 +1,55 @@
+<?xml version="1.0" ?><?xar XSLT?>
+<!-- Implmentation for the Schematron XML Schema Language.
+ http://www.ascc.net/xml/resource/schematron/schematron.html
+
+ Copyright (c) 2000,2001 Rick Jelliffe and Academia Sinica Computing Center, Taiwan
+
+ This software is provided 'as-is', without any express or implied warranty.
+ In no event will the authors be held liable for any damages arising from
+ the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it freely,
+ subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not claim
+ that you wrote the original software. If you use this software in a product,
+ an acknowledgment in the product documentation would be appreciated but is
+ not required.
+
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+
+ 3. This notice may not be removed or altered from any source distribution.
+-->
+
+<!-- Schematron message -->
+
+<xsl:stylesheet
+ version="1.0"
+ xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
+ xmlns:axsl="http://www.w3.org/1999/XSL/TransformAlias">
+
+<xsl:import href="iso_schematron_skeleton_for_xslt1.xsl"/>
+
+<xsl:template name="process-prolog">
+ <axsl:output method="text" />
+</xsl:template>
+
+<!-- use default rule for process-root: copy contens / ignore title -->
+<!-- use default rule for process-pattern: ignore name and see -->
+<!-- use default rule for process-name: output name -->
+<!-- use default rule for process-assert and process-report:
+ call process-message -->
+
+<xsl:template name="process-message">
+ <xsl:param name="pattern" />
+ <xsl:param name="role" />
+ <axsl:message>
+ <xsl:apply-templates mode="text"
+ /> (<xsl:value-of select="$pattern" />
+ <xsl:if test="$role"> / <xsl:value-of select="$role" />
+ </xsl:if>)</axsl:message>
+</xsl:template>
+
+</xsl:stylesheet> \ No newline at end of file
diff --git a/src/lxml/isoschematron/resources/xsl/iso-schematron-xslt1/iso_schematron_skeleton_for_xslt1.xsl b/src/lxml/isoschematron/resources/xsl/iso-schematron-xslt1/iso_schematron_skeleton_for_xslt1.xsl
new file mode 100644
index 00000000..b0e7175c
--- /dev/null
+++ b/src/lxml/isoschematron/resources/xsl/iso-schematron-xslt1/iso_schematron_skeleton_for_xslt1.xsl
@@ -0,0 +1,1796 @@
+<?xml version="1.0"?><?xar XSLT?>
+
+<!--
+ OVERVIEW
+
+ ASCC/Schematron.com Skeleton Module for ISO Schematron (for XSLT1 systems)
+
+ ISO Schematron is a language for making assertion about the presence or absence
+ of patterns in XML documents. It is typically used for as a schema language, or
+ to augment existing schema languages, and to check business rules. It is very
+ powerful, yet quite simple: a developer only need know XPath and about five other
+ elements.
+
+ This is an open source implementation of ISO Schematron in XSLT. Although ISO does
+ not allow reference implementations which might compete with the text of the
+ standard, this code has been compiled by Rick Jelliffe, inventor of Schematron
+ and editor of the ISO standard; so developers can certainly use it as an
+ unofficial reference implementation for clarification.
+
+ This implementation is based on one by Oliver Becker. API documentation is
+ available separately; try www.schematron.com for this. Funding for this
+ stylesheet over the years has come from Topologi Pty. Ltd., Geotempo Ltd.,
+ and ASCC, Tapei.
+
+ There are two versions of this skeleton: one is tailored for XSLT1 processors
+ and the other is tailored for XSLT2 processors. Future versions of the
+ XSLT2 skeleton may support more features than that the XSLT 1 skeleton.
+-->
+<!--
+ TIPS
+
+ A tip for new users of Schematron: make your assertions contain positive messages
+ about what is expected, rather than error messages. For example, use the form
+ "An X should have a Y, because Z".
+
+ Another tip is that Schematron provides an
+ element <sch:ns> for declaring the namespaces and prefixes used in Xpaths in
+ attribute values; it does not extend the XML Namespaces mechanism: if a name
+ in an XPath has a prefix, there must be an <sch:ns> element for that prefix; if
+ a name in an XPath does not have a prefix, it is always in no namespace.
+
+ A tip for implementers of Schematron, either using this API or re-implementing it:
+ make the value of the diagnostics, flags and richer features available if possible;
+ Schematron has many of the optional richer features which, if implemented, provide
+ a compelling alternative approach to validation and business-rules checking compared
+ to other schema languages and programs.
+
+ If you create your own meta-stylesheet to override this one, it is a
+ good idea to have both in the same directory and to run the stylesheet
+ from that directory, as many XSLT implementations have ideosyncratic
+ handling of URLs: keep it simple.
+-->
+
+
+<!--
+ INVOCATION INFORMATION
+
+ The following parameters are available
+
+ phase NMTOKEN | "#ALL" (default) Select the phase for validation
+ allow-foreign "true" | "false" (default) Pass non-Schematron elements to the generated stylesheet
+ sch.exslt.imports semi-colon delimited string of filenames for some EXSLT implementations
+ message-newline "true" (default) | "false" Generate an extra newline at the end of messages
+ optimize "visit-no-attributes"
+ debug "true" | "false" (default) Debug mode lets compilation continue despite problems
+ attributes "true" | "false" (Autodetecting) Use only when the schema has no attributes as the context nodes
+ only-child-elements "true" | "false" (Autodetecting) Use only when the schema has no comments
+ or PI as the context nodes
+
+ The following parameters can be specified as Schematron variables in diagnostics, assertions and so on.
+ fileNameParameter string
+ fileDirParameter string
+ archiveNameParameter string In case of ZIP files
+ archiveDirParameter string In case of ZIP files
+ output-encoding Use when outputting to XML
+
+ Experimental: USE AT YOUR OWN RISK
+ visit-text "true" "false" Also visist text nodes for context. WARNING: NON_STARDARD.
+ select-contents '' | 'key' | '//' Select different implementation strategies
+
+ Conventions: Meta-stylesheets that override this may use the following parameters
+ generate-paths=true|false generate the @location attribute with XPaths
+ diagnose= yes | no Add the diagnostics to the assertion test in reports
+ terminate= yes | no Terminate on the first failed assertion or successful report
+-->
+
+<!--
+ XSLT VERSION SUPPORT
+
+ XSLT 1:
+ A schema using the standard XSLT 1 query binding will have a /schema/@queryBinding='xslt' or
+ nothing.
+
+ * Note: XT does not implement key() and will die if given it.
+ * Add all formal parameters to default templates
+ * Fix missing apply-templates from process-ns and add params back
+
+ EXSLT: Experimental support
+ A schema using the EXSLT query binding will have a /schema/@queryBinding='exslt'.
+ It is built on XSLT 1. After experience is gained, this binding is expected to be
+ formalized as part of ISO Schematron, which currently reserves the "exslt" name for this purpose.
+
+ Some EXSLT engines have the extra functions built-in. For these, there is no need to
+ provide library locations. For engines that require the functions, either hard code
+ them in this script or provide them on the command-line argument.
+
+-->
+<!--
+ PROCESS INFORMATION
+
+ This stylesheet compiles a Schematron schema (*.sch) into XSLT code (*.xsl).
+ The generated XSLT code can then be run against an XML file (*.xml, etc) and
+ will produce validation results.
+
+ The output of validation results is performed using named templates (process-*).
+ These can be overridden easily by making a new XSLT stylesheet that imports this
+ stylesheet but has its own version of the relevant process-* templates. Several
+ of these invoking stylesheets are available: "iso_svrl.xsl", for example generates
+ ISO Schematron Validation Report Language format results.
+
+ In this version of the stylesheet, the ISO feature called "abstract patterns" is
+ implemented using macro processing: a prior XSLT stage to which converts uses
+ of abstract patterns into normal patterns. If you do not use abstract patterns,
+ it is not necessary to preprocess the schema.
+
+ To summarize, a basic process flow for some commandline processor is like this:
+ XSLT -input=xxx.sch -output=xxx.xsl -stylesheet=iso_schematron_skeleton.xsl
+ XSLT -input=document.xml -output=xxx-document.results -stylesheet=xxx.xsl
+
+ iso_svrl.xslt is an implementation of Schematron that can use this skeleton and
+ generate ISO SVRL reports. A process flow for some commandline processor would
+ be like this:
+ XSLT -input=xxx.sch -output=xxx.xsl -stylesheet=iso_svrl.xsl
+ XSLT -input=document.xml -output=xxx-document.results -stylesheet=xxx.xsl
+
+ It is not impossible that ultimately a third stage, to handle macro-preprocessing
+ and inclusion, might be necessary. (The trade-off is in making this XSLT more
+ complex compared to making the outer process more complex.)
+
+ This version has so far been tested with
+ Saxon 8
+ MSXML 4 (or 6?)
+
+ Please note that if you are using SAXON and JAXP, then you should use
+ System.setProperty("javax.xml.transform.TransformerFactory",
+ "net.sf.saxon.TransformerFactoryImpl");
+ rather than
+ System.setProperty("javax.xml.xpath.TransformerFactory",
+ "net.sf.saxon.TransformerFactoryImpl");
+ which is does not work, at least for the versions of SAXON we tried.
+-->
+<!--
+ LEGAL INFORMATION
+
+ Copyright (c) 2000-2008 Rick Jelliffe and Academia Sinica Computing Center, Taiwan
+
+ This software is provided 'as-is', without any express or implied warranty.
+ In no event will the authors be held liable for any damages arising from
+ the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it freely,
+ subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not claim
+ that you wrote the original software. If you use this software in a product,
+ an acknowledgment in the product documentation would be appreciated but is
+ not required.
+
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+
+ 3. This notice may not be removed or altered from any source distribution.
+-->
+<!--
+ NOTE: Compared to the iso_schematron_skeleton_for_saxon.xsl code, this version is currently missing
+ 1) localization
+ 2) properties
+ 3) pattern/@documents
+
+ VERSION INFORMATION
+ 2009-02-25 RJ
+ * Fix up variable names so none are used twice in same template
+ * Tested on SAXON 9, Xalan 2.7.1. Partly tested MSXML.
+ 2008-09-19 RJ
+ * Add mode schematron-select-full-path and param full-path-notation
+
+ 2008-08-11
+ * TT report/@flag was missing
+ 2008-08-06
+ * TT Top-level lets need to be implemented using xsl:param not xsl:variable
+ * TT xsl:param/@select must have XPath or not be specified
+
+ Version: 2008-07-28
+ * KH schematron-get-full-path-3 has [index] even on top step
+ * RJ fix schematron-get-full-path to have namespace predicate, I don't know why this was removed
+
+ Version: 2008-07-24
+ * RJ clean out commented out namespace handling code
+ * RJ add support for experimental non-standard attribute report/@action
+ and assert/@action, and add parameter not in the published API (should
+ not break anything, it is XSLT1)
+ * RJ Remove remaining XSLT2 code for ease of reading
+
+ Version: 2008-07-14 minor update for inclusion experiments
+ * RJ Clean up zero-length fragment test on include
+ * RJ Add experimental support for include containers
+ * RJ For path generation, test for //iso:schema not just /iso:schema, for potential embedded Schematron support
+ * RJ Don't generate double error messages for old namespace elements
+ * RJ Experimental iso:rule/iso:title just kept as comment (bigger request Uche Ogbuji)
+ * RJ Remove spurious debug messages
+ * RJ Fix bug that prevented including patterns in this (report Roger
+ Costello)
+
+ Version: 2007-10-17
+ From this version on I am forking XSLT2 support to a different version of the script.
+ This is due to the increasingly horrible state of the namespace handling code as well
+ as other inconsistencies between the major implementations of different versions.
+ The intent is that future versions of this will have XSLT2 isms removed and be simplified
+ to cope with only XSLT1 and EXLST. Note that though this version is called
+ iso_schematron_skeleton_for_xslt1, the various meta-stylesheets will continue to just call
+ iso_schematron_skeleton: it is up to you to rename the stylesheet to the one you want to
+ use.
+
+ * RJ fix FULL-PATH problem with attribute names
+
+
+ Version: 2007-07-19
+ Accept most changes in David Carlisle's fork, but continue as XSLT1 script:
+ http://dpcarlisle.blogspot.com/search/label/schematron
+ * DPC Remove "optimize" parameter
+ * DPC Add autodetecting optimize parameter attribute to skip checking attribute
+ context
+ * DPC Add autodetecting optimize parameter only-child-elements turn off checking for
+ comments and PIs
+ * DPC (Experimental: NON_STANDARD DANGER!) Add param visit-text to viist text
+ nodes too for context
+ * DPC Fix inclusion syntax to allow #
+ * DPC Priorities count up from 1000 not down from 4000 to allow more rules
+ * RJ Add new template for titles of schemas, with existing behaviour.
+ Override process-schema-title for custom processing of title
+
+
+ Version: 2007-04-04
+ * RJ debug mode param
+ * RJ alter mixed test to only test mixed branches, so the same document
+ could have old and new namespaces schemas in it, but each schema must
+ be distinct, just so as not to overconstrain things.
+ * KH zero-length include/@href is fatal error, but allow debug mode
+ * SB add hint on SAXON and JAXP
+ * DC generate-full-path-1 generates XLST1 code by default
+ Version: 2007-03-05
+ * AS Typo for EXSLT randome, improve comment
+ * KH get-schematron-full-path-2 needs to apply to attributes too
+ * DP document policy on extensions better
+ * DC use copy-of not copy for foreign elements
+ * DC add generate-path-2
+ * DC don't try to apply templates to attribute axis on attribute nodes, to
+ stop SAXON warning.
+ * RJ improve reporting of typos
+
+ Version: 2007-02-08
+ * KH Schematron fullpath implementation: @* handled twice and / missing
+ * KH Change stylesheetbody from named template to mode to allow implementers more flexibility.
+ Move process-ns to outside the stylesheet body.
+ * DP, FG, fix handling of xslt:key
+ * FG no iso:title/@class
+ * Experimental optimization 'visit-no-attributes'
+ * KH Experimental added schematron-get-full-path-2 which gives prefixed version for humans
+ * DC Move stylesheet/@version generation to after namespace handling
+ * DC, FG EXSLT namespace handling code
+ * FG add ref and commented code from FG's page on namespaces
+ * Start adding normalize-space() to parameter code
+ * Add a space between diagnostics
+
+ Version: 2007-01-22
+ * DP change = ($start) to = $start and =($phase) to =$phase
+ to run under Saxon 8.8j
+ * FG better title section using ( @id | sch:title)[last()]
+ * Default query language binding is "xslt" not "xslt1"
+
+ Version: 2007-01-19
+ * Simplify message newline code
+ * Remove termination and xpath appending to message options:
+ factor out as iso_schematron_terminator.xsl
+ * Comment out XSLT2 namespace fix temporarily
+
+ Version: 2007-01-18 (First beta candidate for comment)
+ * DC remove xml:space="preserve"
+ * FG improve comment on import statement
+ * DC improve comments on invocation section
+ * Add exploratory support for sch:schema[@queryBinding='xpath']
+ by allowing it and warning as lets are found
+ * Be strict about queryBinding spelling errors
+ * Extra comments on the different queryBindings
+ * KH Add option "message-paths" to generate XPath from output
+ * KH Add option "terminate" to halt with an error after the first assertion
+ * KH refactor paths in schematron-full-path
+ * Improve (?) namespace handling: no dummy attributes for prefix "xsl" generated
+
+ Version: 2007-01-15
+ * FG fix for calling templates
+ * Add formal parameters to default templates: may help XSLT 2
+ * Fix get-schematron-full-path
+ * Include skeleton1-6 is commented out by default
+
+ Version:2007-01-12 (Pre-beta release to Schematron-love-in maillist)
+ * Add many extra parameters to the process-* calls, so that almost
+ all the information in the schema can be provided to client programs.
+ Also, rearrange the parameters to fit in with the ISO schema, which
+ has "rich" and "linkable" attribute groups.
+ * Warn on diagnostics with no ID once only
+ * Improved path reporting, to handle for namespaces
+ * Add process-title dummy template for API
+ * Add command-line parameter allow-foreign (true|false) to suppress
+ warnings one foreign elements and pass them through to the generated
+ stylesheet
+ * remove legacy templates for the old ASCC namespace and no namespace,
+ and use an import statement instead. Much cleaner now!
+ * patterns use @id not @name
+ * titles can contain sub-elements
+ * start change sch:rule to allow attributes, PIs and comments
+ * the default process-* for inline elements add a leading and trailing
+ space, to reduce the chance of concatenation.
+ * add comments to make the generated code clearer
+
+ Version:2006-11-07 (ISO: first release private to schematron-love-in maillist for review)
+ * Duplicate pattern templates, for handling ISO namespace
+ * Add priority onto default and paragraph templates
+ * Add namespace checks
+ * Handle key in xsl namespace not iso
+ * Add include
+ * Improve namespace handling
+ * Preliminary XSLT2 and EXSLT support
+ * Refactor iso:schema for clarity
+
+ Version: 2003-05-26
+ * Fix bug with key
+ Version: 2003-04-16
+ * handle 1.6 let expressions
+ * make key use XSLT names, and allow anywhere
+ Version: 2001-06-13
+ * same skeleton now supports namespace or no namespace
+ * parameters to handlers updated for all 1.5 attributes
+ * diagnostic hints supported: command-line option diagnose=yes|no
+ * phases supported: command-line option phase=#ALL|...
+ * abstract rules
+ * compile-time error messages
+ * add utility routine generate-id-from-path
+
+ Contributors: Rick Jelliffe (original), Oliver Becker (architecture, XSLT2),
+ Miloslav Nic (diagnostic, phase, options), Ludwig Svenonius (abstract)
+ Uche Ogbuji (misc. bug fixes), Jim Ancona (SAXON workaround),
+ Francis Norton (generate-id-from-path), Robert Leftwich, Bryan Rasmussen,
+ Dave Pawson (include, fallback), Florent Georges (namespaces, exslt, attribute
+ context), Benoit Maisonny (attribute context), John Dumps (process-message newline),
+ Cliff Stanford (diagnostics and other newlines)
+
+
+ KNOWN TYPICAL LIMITATIONS:
+ * Don't use <sch:ns prefix="xsl" .../> with a namespace other than the standard
+ XSLT one. This would be a bizarre thing to do anyway.
+ * Don't use other prefixes for the XSLT namespace either; some implementations will
+ not handle it correctly.
+
+ EXTENSIONS:
+ ISO Schematron is designed as a framework with some standard query language
+ bindings. If you need to support other features, please do so safely by making
+ up your own @queryLanguage name: this makes it clear that your schema requires
+ special features. For example, default ISO Schematron does not support user
+ defined functions; so if you want to use the user defined function feature
+ in XSLT, you need to have a schema with some queryBinding attribute name like
+ "XSLT-with-my-functions" or whatever.
+-->
+
+
+
+
+<xsl:stylesheet version="1.0"
+ xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
+ xmlns:axsl="http://www.w3.org/1999/XSL/TransformAlias"
+ xmlns:sch="http://www.ascc.net/xml/schematron"
+ xmlns:iso="http://purl.oclc.org/dsdl/schematron"
+ xmlns:exsl="http://exslt.org/common"
+ xmlns:msxsl="urn:schemas-microsoft-com:xslt"
+ extension-element-prefixes="exsl msxsl"
+ >
+<!-- This program implements ISO Schematron, except for abstract patterns which require a preprocess. -->
+
+
+<xsl:namespace-alias stylesheet-prefix="axsl" result-prefix="xsl"/>
+
+
+<!-- Category: top-level-element -->
+<xsl:output method="xml" omit-xml-declaration="no" standalone="yes" indent="yes"/>
+
+
+<xsl:param name="phase">
+ <xsl:choose>
+ <xsl:when test="//sch:schema/@defaultPhase">
+ <xsl:value-of select="//sch:schema/@defaultPhase"/>
+ </xsl:when>
+ <xsl:when test="//iso:schema/@defaultPhase">
+ <xsl:value-of select="//iso:schema/@defaultPhase"/>
+ </xsl:when>
+ <xsl:otherwise>#ALL</xsl:otherwise>
+ </xsl:choose>
+</xsl:param>
+
+<xsl:param name="allow-foreign">false</xsl:param>
+
+<xsl:param name="message-newline">true</xsl:param>
+
+<!-- DPC set to true if contexts should be checked on attribute nodes
+ defaults to true if there is any possibility that a context could match an attribute,
+ err on the side if caution, a context of *[.='@'] would cause this param to defualt to true
+ even though @ is in a string
+-->
+<xsl:param name="attributes">
+ <xsl:choose>
+ <xsl:when test="//iso:rule[contains(@context,'@') or contains(@context,'attribute')]">true</xsl:when>
+ <xsl:otherwise>false</xsl:otherwise>
+ </xsl:choose>
+</xsl:param>
+
+<!-- DPC set to true if contexts should be checked on just elements in the child axis
+ defaults to true if there is any possibility that a context could match an comment or PI
+ err on the side if caution, a context of *[.='('] would cause this param to defualt to true
+ even though ( is in a string, but node() comment() and processing-instruction() all have a (
+-->
+<xsl:param name="only-child-elements">
+ <xsl:choose>
+ <xsl:when test="//iso:rule[contains(@context,'(')]">true</xsl:when>
+ <xsl:otherwise>false</xsl:otherwise>
+ </xsl:choose>
+</xsl:param>
+
+<!-- DPC set to true if contexts should be checked on text nodes nodes (if only-child-elements is false)
+ THIS IS NON CONFORMANT BEHAVIOUR JUST FOR DISCUSSION OF A POSSIBLE CHANGE TO THE
+ SPECIFICATION. THIS PARAM SHOULD GO IF THE FINAL DECISION IS THAT THE SPEC DOES NOT CHANGE.
+ Always defaults to false
+-->
+<xsl:param name="visit-text" select="'false'"/>
+
+<!-- DPC
+ When selecting contexts the specified behaviour is
+ @*|node()[not(self::text())]
+ The automatic settings may use
+ node()[not(self::text())]
+ @*|*
+ *
+ instead for schema for which they are equivalent.
+ If the params are set explictly the above may be used, and also either if
+ @*
+ @*|node()
+ in all cases the result may not be equivalent, for example if you specify no attributes and the schema
+ does have attribute contexts they will be silently ignored.
+
+ after testing it turns out that
+ node()[not(self::text())] is slower in saxon than *|comment()|processing-instruction()
+ which I find a bit surprising but anyway I'll use the longr faster version.
+-->
+<xsl:variable name="context-xpath">
+ <xsl:if test="$attributes='true'">@*|</xsl:if>
+ <xsl:choose>
+ <xsl:when test="$only-child-elements='true'">*</xsl:when>
+ <xsl:when test="$visit-text='true'">node()</xsl:when>
+ <xsl:otherwise>*|comment()|processing-instruction()</xsl:otherwise>
+ </xsl:choose>
+</xsl:variable>
+
+<!-- DPC if this is set to
+ '' use recursive templates to iterate over document tree,
+ 'key' select all contexts with a key rather than walking the tree explictly in each mode
+ '//' select all contexts with // a key rather than walking the tree explictly in each mode (XSLT2 only)
+-->
+<xsl:param name="select-contexts" select="''"/>
+
+
+<xsl:param name="output-encoding"/>
+<!-- e.g. saxon file.xml file.xsl "sch.exslt.imports=.../string.xsl;.../math.xsl" -->
+<xsl:param name="sch.exslt.imports"/>
+
+<!-- Set the language code for messages -->
+<xsl:param name="langCode">default</xsl:param>
+
+<xsl:param name="debug">false</xsl:param>
+
+
+<!-- Set the default for schematron-select-full-path, i.e. the notation for svrl's @location-->
+<xsl:param name="full-path-notation">1</xsl:param>
+
+<!-- Simple namespace check -->
+<xsl:template match="/">
+ <xsl:if test="//sch:*[ancestor::iso:* or descendant::iso:*]">
+ <xsl:message>Schema error: Schematron elements in old and new namespaces found</xsl:message>
+ <xsl:if test=" $debug = 'false' " />
+ </xsl:if>
+
+ <xsl:apply-templates />
+</xsl:template>
+
+
+<!-- ============================================================== -->
+<!-- ISO SCHEMATRON SCHEMA ELEMENT -->
+<!-- Not handled: Abstract patterns. A pre-processor is assumed. -->
+<!-- ============================================================== -->
+
+<!-- SCHEMA -->
+<!-- Default uses XSLT 1 -->
+<xsl:template match="iso:schema[not(@queryBinding) or @queryBinding='xslt'
+ or @queryBinding='xslt1' or @queryBinding='XSLT' or @queryBinding='XSLT1'
+ or @queryBinding='xpath']">
+ <xsl:if test="
+ @queryBinding='xslt1' or @queryBinding='XSLT' or @queryBinding='XSLT1'">
+ <xsl:message>Schema error: in the queryBinding attribute, use 'xslt'</xsl:message>
+ </xsl:if>
+ <axsl:stylesheet>
+ <xsl:apply-templates select="iso:ns"/>
+ <!-- Handle the namespaces before the version attribute: reported to help SAXON -->
+ <xsl:attribute name="version">1.0</xsl:attribute>
+
+ <xsl:apply-templates select="." mode="stylesheetbody"/>
+ <!-- was xsl:call-template name="stylesheetbody"/ -->
+ </axsl:stylesheet>
+</xsl:template>
+
+<!-- Using EXSLT with all modeles (except function module: not applicable) -->
+<xsl:template match="iso:schema[@queryBinding='exslt']" priority="10">
+ <xsl:comment>This XSLT was automatically generated from a Schematron schema.</xsl:comment>
+ <axsl:stylesheet
+ xmlns:date="http://exslt.org/dates-and-times"
+ xmlns:dyn="http://exslt.org/dynamic"
+ xmlns:exsl="http://exslt.org/common"
+ xmlns:math="http://exslt.org/math"
+ xmlns:random="http://exslt.org/random"
+ xmlns:regexp="http://exslt.org/regular-expressions"
+ xmlns:set="http://exslt.org/sets"
+ xmlns:str="http://exslt.org/strings"
+ extension-element-prefixes="date dyn exsl math random regexp set str" >
+
+ <xsl:apply-templates select="iso:ns"/>
+ <!-- Handle the namespaces before the version attribute: reported to help SAXON -->
+ <xsl:attribute name="version">1.0</xsl:attribute>
+
+ <xsl:apply-templates select="." mode="stylesheetbody"/>
+ <!-- was xsl:call-template name="stylesheetbody"/ -->
+ </axsl:stylesheet>
+</xsl:template>
+
+
+<!-- Default uses XSLT 1 -->
+<xsl:template match="iso:schema" priority="-1">
+ <xsl:message terminate="yes" >Fail: This implementation of ISO Schematron does not work with
+ schemas using the "<xsl:value-of select="@queryBinding"/>" query language.</xsl:message>
+</xsl:template>
+
+<xsl:template match="*" mode="stylesheetbody">
+ <!--xsl:template name="stylesheetbody"-->
+ <xsl:comment>Implementers: please note that overriding process-prolog or process-root is
+ the preferred method for meta-stylesheets to use where possible. </xsl:comment><xsl:text>&#10;</xsl:text>
+
+ <!-- These parameters may contain strings with the name and directory of the file being
+ validated. For convenience, if the caller only has the information in a single string,
+ that string could be put in fileDirParameter. The archives parameters are available
+ for ZIP archives.
+ -->
+
+ <axsl:param name="archiveDirParameter" />
+ <axsl:param name="archiveNameParameter" />
+ <axsl:param name="fileNameParameter" />
+ <axsl:param name="fileDirParameter" />
+
+ <xsl:call-template name="iso:exslt.add.imports" />
+ <xsl:text>&#10;&#10;</xsl:text><xsl:comment>PHASES</xsl:comment><xsl:text>&#10;</xsl:text>
+ <xsl:call-template name="handle-phase"/>
+ <xsl:text>&#10;&#10;</xsl:text><xsl:comment>PROLOG</xsl:comment><xsl:text>&#10;</xsl:text>
+ <xsl:call-template name="process-prolog"/>
+ <xsl:text>&#10;&#10;</xsl:text><xsl:comment>KEYS</xsl:comment><xsl:text>&#10;</xsl:text>
+ <xsl:apply-templates mode="do-keys" select="xsl:key "/>
+ <xsl:text>&#10;&#10;</xsl:text><xsl:comment>DEFAULT RULES</xsl:comment><xsl:text>&#10;</xsl:text>
+ <xsl:call-template name="generate-default-rules" />
+ <xsl:text>&#10;&#10;</xsl:text><xsl:comment>SCHEMA METADATA</xsl:comment><xsl:text>&#10;</xsl:text>
+ <xsl:call-template name="handle-root"/>
+ <xsl:text>&#10;&#10;</xsl:text><xsl:comment>SCHEMATRON PATTERNS</xsl:comment><xsl:text>&#10;</xsl:text>
+
+ <xsl:apply-templates select="*[not(self::iso:ns)] " />
+</xsl:template>
+
+ <xsl:template name="iso:exslt.add.imports">
+ <xsl:param name="imports" select="$sch.exslt.imports"/>
+ <xsl:choose>
+ <xsl:when test="contains($imports, ';')">
+ <axsl:import href="{ substring-before($imports, ';') }"/>
+ <xsl:call-template name="iso:exslt.add.imports">
+ <xsl:with-param name="imports" select="substring-after($imports, ';')"/>
+ </xsl:call-template>
+ </xsl:when>
+ <xsl:when test="$imports">
+ <axsl:import href="{ $imports }"/>
+ </xsl:when>
+ </xsl:choose>
+ </xsl:template>
+
+<xsl:template name="handle-phase" >
+ <xsl:if test="not(normalize-space( $phase ) = '#ALL')">
+ <xsl:if test="not(iso:phase[@id = normalize-space( $phase )])">
+ <xsl:message>Phase Error: no phase with name <xsl:value-of select="normalize-space( $phase )"
+ /> has been defined.</xsl:message>
+ </xsl:if>
+ </xsl:if>
+</xsl:template>
+
+<xsl:template name="generate-default-rules">
+ <xsl:text>&#10;&#10;</xsl:text>
+ <xsl:comment>MODE: SCHEMATRON-SELECT-FULL-PATH</xsl:comment><xsl:text>&#10;</xsl:text>
+ <xsl:comment>This mode can be used to generate an ugly though full XPath for locators</xsl:comment><xsl:text>&#10;</xsl:text>
+ <axsl:template match="*" mode="schematron-select-full-path">
+ <xsl:choose>
+ <xsl:when test=" $full-path-notation = '1' ">
+ <!-- Use for computers, but rather unreadable for humans -->
+ <axsl:apply-templates select="." mode="schematron-get-full-path"/>
+ </xsl:when>
+ <xsl:when test=" $full-path-notation = '2' ">
+ <!-- Use for humans, but no good for paths unless namespaces are known out-of-band -->
+ <axsl:apply-templates select="." mode="schematron-get-full-path-2"/>
+ </xsl:when>
+ <xsl:when test=" $full-path-notation = '3' ">
+ <!-- Obsolescent. Use for humans, but no good for paths unless namespaces are known out-of-band -->
+ <axsl:apply-templates select="." mode="schematron-get-full-path-3"/>
+ </xsl:when>
+
+ <xsl:otherwise >
+ <!-- Use for computers, but rather unreadable for humans -->
+ <axsl:apply-templates select="." mode="schematron-get-full-path"/>
+ </xsl:otherwise>
+ </xsl:choose>
+ </axsl:template>
+
+
+ <xsl:text>&#10;&#10;</xsl:text>
+ <xsl:comment>MODE: SCHEMATRON-FULL-PATH</xsl:comment><xsl:text>&#10;</xsl:text>
+ <xsl:comment>This mode can be used to generate an ugly though full XPath for locators</xsl:comment><xsl:text>&#10;</xsl:text>
+ <axsl:template match="*" mode="schematron-get-full-path">
+ <axsl:apply-templates select="parent::*" mode="schematron-get-full-path"/>
+
+ <!-- XSLT1 syntax -->
+
+ <axsl:text>/</axsl:text>
+ <axsl:choose>
+ <axsl:when test="namespace-uri()=''">
+ <axsl:value-of select="name()"/>
+ <axsl:variable name="p_1" select="1+
+ count(preceding-sibling::*[name()=name(current())])" />
+ <axsl:if test="$p_1&gt;1 or following-sibling::*[name()=name(current())]">
+ <xsl:text/>[<axsl:value-of select="$p_1"/>]<xsl:text/>
+ </axsl:if>
+ </axsl:when>
+ <axsl:otherwise>
+ <axsl:text>*[local-name()='</axsl:text>
+ <axsl:value-of select="local-name()"/><axsl:text>' and namespace-uri()='</axsl:text>
+ <axsl:value-of select="namespace-uri()"/>
+ <axsl:text>']</axsl:text>
+ <axsl:variable name="p_2" select="1+
+ count(preceding-sibling::*[local-name()=local-name(current())])" />
+ <axsl:if test="$p_2&gt;1 or following-sibling::*[local-name()=local-name(current())]">
+ <xsl:text/>[<axsl:value-of select="$p_2"/>]<xsl:text/>
+ </axsl:if>
+ </axsl:otherwise>
+ </axsl:choose>
+ </axsl:template>
+
+
+ <axsl:template match="@*" mode="schematron-get-full-path">
+
+ <!-- XSLT1 syntax -->
+ <axsl:text>/</axsl:text>
+ <axsl:choose>
+ <axsl:when test="namespace-uri()=''">@<axsl:value-of
+ select="name()"/></axsl:when>
+ <axsl:otherwise>
+ <axsl:text>@*[local-name()='</axsl:text>
+ <axsl:value-of select="local-name()"/>
+ <axsl:text>' and namespace-uri()='</axsl:text>
+ <axsl:value-of select="namespace-uri()"/>
+ <axsl:text>']</axsl:text>
+ </axsl:otherwise>
+ </axsl:choose>
+
+ </axsl:template>
+
+
+ <xsl:text>&#10;&#10;</xsl:text>
+
+ <xsl:comment>MODE: SCHEMATRON-FULL-PATH-2</xsl:comment>
+ <xsl:text>&#10;</xsl:text>
+ <xsl:comment>This mode can be used to generate prefixed XPath for humans</xsl:comment>
+ <xsl:text>&#10;</xsl:text>
+ <!--simplify the error messages by using the namespace prefixes of the
+ instance rather than the generic namespace-uri-styled qualification-->
+ <axsl:template match="node() | @*" mode="schematron-get-full-path-2">
+ <!--report the element hierarchy-->
+ <axsl:for-each select="ancestor-or-self::*">
+ <axsl:text>/</axsl:text>
+ <axsl:value-of select="name(.)"/>
+ <axsl:if test="preceding-sibling::*[name(.)=name(current())]">
+ <axsl:text>[</axsl:text>
+ <axsl:value-of
+ select="count(preceding-sibling::*[name(.)=name(current())])+1"/>
+ <axsl:text>]</axsl:text>
+ </axsl:if>
+ </axsl:for-each>
+ <!--report the attribute-->
+ <axsl:if test="not(self::*)">
+ <axsl:text/>/@<axsl:value-of select="name(.)"/>
+ </axsl:if>
+ </axsl:template>
+
+ <xsl:text>&#10;&#10;</xsl:text>
+ <xsl:comment>MODE: GENERATE-ID-FROM-PATH </xsl:comment><xsl:text>&#10;</xsl:text>
+ <!-- repeatable-id maker derived from Francis Norton's. -->
+ <!-- use this if you need generate ids in separate passes,
+ because generate-id() is not guaranteed to produce the same
+ results each time. These ids are not XML names but closer to paths. -->
+ <axsl:template match="/" mode="generate-id-from-path"/>
+ <axsl:template match="text()" mode="generate-id-from-path">
+ <axsl:apply-templates select="parent::*" mode="generate-id-from-path"/>
+ <axsl:value-of select="concat('.text-', 1+count(preceding-sibling::text()), '-')"/>
+ </axsl:template>
+ <axsl:template match="comment()" mode="generate-id-from-path">
+ <axsl:apply-templates select="parent::*" mode="generate-id-from-path"/>
+ <axsl:value-of select="concat('.comment-', 1+count(preceding-sibling::comment()), '-')"/>
+ </axsl:template>
+ <axsl:template match="processing-instruction()" mode="generate-id-from-path">
+ <axsl:apply-templates select="parent::*" mode="generate-id-from-path"/>
+ <axsl:value-of
+ select="concat('.processing-instruction-', 1+count(preceding-sibling::processing-instruction()), '-')"/>
+ </axsl:template>
+ <axsl:template match="@*" mode="generate-id-from-path">
+ <axsl:apply-templates select="parent::*" mode="generate-id-from-path"/>
+ <axsl:value-of select="concat('.@', name())"/>
+ </axsl:template>
+ <axsl:template match="*" mode="generate-id-from-path" priority="-0.5">
+ <axsl:apply-templates select="parent::*" mode="generate-id-from-path"/>
+ <axsl:text>.</axsl:text>
+<!--
+ <axsl:choose>
+ <axsl:when test="count(. | ../namespace::*) = count(../namespace::*)">
+ <axsl:value-of select="concat('.namespace::-',1+count(namespace::*),'-')"/>
+ </axsl:when>
+ <axsl:otherwise>
+-->
+ <axsl:value-of
+ select="concat('.',name(),'-',1+count(preceding-sibling::*[name()=name(current())]),'-')"/>
+<!--
+ </axsl:otherwise>
+ </axsl:choose>
+-->
+ </axsl:template>
+
+
+ <xsl:comment>MODE: SCHEMATRON-FULL-PATH-3</xsl:comment>
+
+ <xsl:text>&#10;</xsl:text>
+ <xsl:comment>This mode can be used to generate prefixed XPath for humans
+ (Top-level element has index)</xsl:comment>
+ <xsl:text>&#10;</xsl:text>
+ <!--simplify the error messages by using the namespace prefixes of the
+ instance rather than the generic namespace-uri-styled qualification-->
+ <axsl:template match="node() | @*" mode="schematron-get-full-path-3">
+ <!--report the element hierarchy-->
+ <axsl:for-each select="ancestor-or-self::*">
+ <axsl:text>/</axsl:text>
+ <axsl:value-of select="name(.)"/>
+ <axsl:if test="parent::*">
+ <axsl:text>[</axsl:text>
+ <axsl:value-of
+ select="count(preceding-sibling::*[name(.)=name(current())])+1"/>
+ <axsl:text>]</axsl:text>
+ </axsl:if>
+ </axsl:for-each>
+ <!--report the attribute-->
+ <axsl:if test="not(self::*)">
+ <axsl:text/>/@<axsl:value-of select="name(.)"/>
+ </axsl:if>
+ </axsl:template>
+
+ <xsl:text>&#10;&#10;</xsl:text>
+ <xsl:comment>MODE: GENERATE-ID-2 </xsl:comment><xsl:text>&#10;</xsl:text>
+ <!-- repeatable-id maker from David Carlisle. -->
+ <!-- use this if you need generate IDs in separate passes,
+ because generate-id() is not guaranteed to produce the same
+ results each time. These IDs are well-formed XML NMTOKENS -->
+ <axsl:template match="/" mode="generate-id-2">U</axsl:template>
+
+ <axsl:template match="*" mode="generate-id-2" priority="2">
+ <axsl:text>U</axsl:text>
+ <axsl:number level="multiple" count="*"/>
+ </axsl:template>
+
+ <axsl:template match="node()" mode="generate-id-2">
+ <axsl:text>U.</axsl:text>
+ <axsl:number level="multiple" count="*"/>
+ <axsl:text>n</axsl:text>
+ <axsl:number count="node()"/>
+ </axsl:template>
+
+ <axsl:template match="@*" mode="generate-id-2">
+ <axsl:text>U.</axsl:text>
+ <axsl:number level="multiple" count="*"/>
+ <axsl:text>_</axsl:text>
+ <axsl:value-of select="string-length(local-name(.))"/>
+ <axsl:text>_</axsl:text>
+ <axsl:value-of select="translate(name(),':','.')"/>
+ </axsl:template>
+
+
+ <xsl:comment>Strip characters</xsl:comment>
+ <axsl:template match="text()" priority="-1" />
+
+ </xsl:template>
+
+ <xsl:template name="handle-root">
+ <!-- Process the top-level element -->
+ <axsl:template match="/">
+ <xsl:call-template name="process-root">
+ <xsl:with-param
+ name="title" select="(@id | iso:title)[last()]"/>
+ <xsl:with-param name="version" select="'iso'" />
+ <xsl:with-param name="schemaVersion" select="@schemaVersion" />
+ <xsl:with-param name="queryBinding" select="@queryBinding" />
+ <xsl:with-param name="contents">
+ <xsl:apply-templates mode="do-all-patterns"/>
+ </xsl:with-param>
+
+ <!-- "Rich" properties -->
+ <xsl:with-param name="fpi" select="@fpi"/>
+ <xsl:with-param name="icon" select="@icon"/>
+ <xsl:with-param name="id" select="@id"/>
+ <xsl:with-param name="lang" select="@xml:lang"/>
+ <xsl:with-param name="see" select="@see" />
+ <xsl:with-param name="space" select="@xml:space" />
+
+
+ <!-- Non-standard extensions not part of the API yet -->
+ <xsl:with-param name="action" select="@action" />
+ </xsl:call-template>
+ </axsl:template>
+
+
+</xsl:template>
+
+<!-- ============================================================== -->
+<!-- ISO SCHEMATRON ELEMENTS -->
+<!-- ============================================================== -->
+
+ <!-- ISO ACTIVE -->
+ <xsl:template match="iso:active">
+ <xsl:if test="not(@pattern)">
+ <xsl:message>Markup Error: no pattern attribute in &lt;active></xsl:message>
+ </xsl:if>
+
+ <xsl:if test="not(../../iso:pattern[@id = current()/@pattern])
+ and not(../../iso:include)">
+ <xsl:message>Reference Error: the pattern "<xsl:value-of select="@pattern"
+ />" has been activated but is not declared</xsl:message>
+ </xsl:if>
+ </xsl:template>
+
+ <!-- ISO ASSERT and REPORT -->
+ <xsl:template match="iso:assert">
+
+ <xsl:if test="not(@test)">
+ <xsl:message>Markup Error: no test attribute in &lt;assert</xsl:message>
+ </xsl:if>
+ <xsl:text>&#10;&#10; </xsl:text>
+ <xsl:comment>ASSERT <xsl:value-of select="@role" /> </xsl:comment><xsl:text>&#10;</xsl:text>
+
+ <axsl:choose>
+ <axsl:when test="{@test}"/>
+ <axsl:otherwise>
+ <xsl:call-template name="process-assert">
+ <xsl:with-param name="test" select="normalize-space(@test)" />
+ <xsl:with-param name="diagnostics" select="@diagnostics"/>
+ <xsl:with-param name="flag" select="@flag"/>
+
+ <!-- "Rich" properties -->
+ <xsl:with-param name="fpi" select="@fpi"/>
+ <xsl:with-param name="icon" select="@icon"/>
+ <xsl:with-param name="id" select="@id"/>
+ <xsl:with-param name="lang" select="@xml:lang"/>
+ <xsl:with-param name="see" select="@see" />
+ <xsl:with-param name="space" select="@xml:space" />
+
+ <!-- "Linking" properties -->
+ <xsl:with-param name="role" select="@role" />
+ <xsl:with-param name="subject" select="@subject" />
+ </xsl:call-template>
+
+ </axsl:otherwise>
+ </axsl:choose>
+ </xsl:template>
+ <xsl:template match="iso:report">
+
+ <xsl:if test="not(@test)">
+ <xsl:message>Markup Error: no test attribute in &lt;report></xsl:message>
+ </xsl:if>
+
+ <xsl:text>&#10;&#10; </xsl:text>
+ <xsl:comment>REPORT <xsl:value-of select="@role" /> </xsl:comment><xsl:text>&#10;</xsl:text>
+
+ <axsl:if test="{@test}">
+
+ <xsl:call-template name="process-report">
+ <xsl:with-param name="test" select="normalize-space(@test)" />
+ <xsl:with-param name="diagnostics" select="@diagnostics"/>
+ <xsl:with-param name="flag" select="@flag"/>
+
+ <!-- "Rich" properties -->
+ <xsl:with-param name="fpi" select="@fpi"/>
+ <xsl:with-param name="icon" select="@icon"/>
+ <xsl:with-param name="id" select="@id"/>
+ <xsl:with-param name="lang" select="@xml:lang"/>
+ <xsl:with-param name="see" select="@see" />
+ <xsl:with-param name="space" select="@xml:space" />
+
+ <!-- "Linking" properties -->
+ <xsl:with-param name="role" select="@role" />
+ <xsl:with-param name="subject" select="@subject" />
+ </xsl:call-template>
+
+ </axsl:if>
+ </xsl:template>
+
+
+ <!-- ISO DIAGNOSTIC -->
+ <!-- We use a mode here to maintain backwards compatability, instead of adding it
+ to the other mode.
+ -->
+ <xsl:template match="iso:diagnostic" mode="check-diagnostics">
+ <xsl:if test="not(@id)">
+ <xsl:message>Markup Error: no id attribute in &lt;diagnostic></xsl:message>
+ </xsl:if>
+ </xsl:template>
+
+ <xsl:template match="iso:diagnostic" >
+ <xsl:call-template name="process-diagnostic">
+
+ <!-- "Rich" properties -->
+ <xsl:with-param name="fpi" select="@fpi"/>
+ <xsl:with-param name="icon" select="@icon"/>
+ <xsl:with-param name="id" select="@id"/>
+ <xsl:with-param name="lang" select="@xml:lang"/>
+ <xsl:with-param name="see" select="@see" />
+ <xsl:with-param name="space" select="@xml:space" />
+ </xsl:call-template>
+ </xsl:template>
+
+ <!-- ISO DIAGNOSTICS -->
+ <xsl:template match="iso:diagnostics" >
+ <xsl:apply-templates mode="check-diagnostics" select="*" />
+ </xsl:template>
+
+ <!-- ISO DIR -->
+ <xsl:template match="iso:dir" mode="text" >
+ <xsl:call-template name="process-dir">
+ <xsl:with-param name="value" select="@value"/>
+ </xsl:call-template>
+ </xsl:template>
+
+ <!-- ISO EMPH -->
+ <xsl:template match="iso:emph" mode="text">
+
+ <xsl:call-template name="process-emph"/>
+
+ </xsl:template>
+
+ <!-- ISO EXTENDS -->
+ <xsl:template match="iso:extends">
+ <xsl:if test="not(@rule)">
+ <xsl:message>Markup Error: no rule attribute in &lt;extends></xsl:message>
+ </xsl:if>
+ <xsl:if test="not(//iso:rule[@abstract='true'][@id= current()/@rule] )">
+ <xsl:message>Reference Error: the abstract rule "<xsl:value-of select="@rule"
+ />" has been referenced but is not declared</xsl:message>
+ </xsl:if>
+ <xsl:call-template name="IamEmpty" />
+
+ <xsl:if test="//iso:rule[@id=current()/@rule]">
+ <xsl:apply-templates select="//iso:rule[@id=current()/@rule]"
+ mode="extends"/>
+ </xsl:if>
+
+ </xsl:template>
+
+ <!-- KEY: ISO has no KEY -->
+ <!-- NOTE:
+ Key has had a checkered history. Schematron 1.0 allowed it in certain places, but
+ users came up with a different location, which has now been adopted.
+
+ XT, the early XSLT processor, did not implement key and died when it was present.
+ So there are some versions of the Schematron skeleton for XT that strip out all
+ key elements.
+
+ Xalan (e.g. Xalan4C 1.0 and a Xalan4J) also had a funny. A fix involved making
+ a top-level parameter called $hiddenKey and then using that instead of matching
+ "key". This has been removed.
+ -->
+ <xsl:template match="xsl:key" mode="do-keys" >
+ <xsl:if test="not(@name)">
+ <xsl:message>Markup Error: no name attribute in &lt;key></xsl:message>
+ </xsl:if>
+ <xsl:if test="not(@path) and not(@use)">
+ <xsl:message>Markup Error: no path or use attribute in &lt;key></xsl:message>
+ </xsl:if>
+ <xsl:choose>
+ <xsl:when test="parent::iso:rule ">
+ <xsl:call-template name="IamEmpty" />
+ <xsl:choose>
+ <xsl:when test="@path">
+ <axsl:key match="{../@context}" name="{@name}" use="{@path}"/>
+ </xsl:when>
+ <xsl:otherwise>
+ <axsl:key match="{../@context}" name="{@name}" use="{@use}"/>
+ </xsl:otherwise>
+ </xsl:choose>
+ </xsl:when>
+ <xsl:otherwise>
+ <xsl:if test="not(@match) ">
+ <xsl:message>Markup Error: no path or use attribute in &lt;key></xsl:message>
+ </xsl:if>
+ <axsl:key>
+ <xsl:copy-of select="@*"/>
+ </axsl:key>
+ </xsl:otherwise>
+ </xsl:choose>
+ </xsl:template>
+
+ <xsl:template match="xsl:key " /><!-- swallow -->
+
+ <xsl:template match="iso:key " >
+ <xsl:message>Schema error: The key element is not in the ISO Schematron namespace. Use the XSLT namespace.</xsl:message>
+ </xsl:template>
+
+ <!-- ISO INCLUDE -->
+ <!-- This is only a fallback. Include really needs to have been done before this as a separate pass.-->
+
+ <xsl:template match="iso:include[not(normalize-space(@href))]"
+ priority="1">
+ <xsl:if test=" $debug = 'false' ">
+ <xsl:message terminate="yes">Schema error: Empty href= attribute for include directive.</xsl:message>
+ </xsl:if>
+
+ </xsl:template>
+
+ <!-- Extend the URI syntax to allow # refererences -->
+ <!-- Add experimental support for simple containers like /xxx:xxx/iso:pattern to allow better includes -->
+ <xsl:template match="iso:include">
+ <xsl:variable name="document-uri" select="substring-before(concat(@href,'#'), '#')"/>
+ <xsl:variable name="fragment-id" select="substring-after(@href, '#')"/>
+
+ <xsl:choose>
+
+ <xsl:when test="string-length( $document-uri ) = 0 and string-length( $fragment-id ) = 0" >
+ <xsl:message>Error: Impossible URL in Schematron include</xsl:message>
+ </xsl:when>
+
+ <xsl:when test="string-length( $fragment-id ) &gt; 0">
+ <xsl:variable name="theDocument_1" select="document( $document-uri,/ )" />
+ <xsl:variable name="theFragment_1" select="$theDocument_1//iso:*[@id= $fragment-id ]" />
+ <xsl:if test=" $theFragment_1/self::iso:schema ">
+ <xsl:message>Schema error: Use include to include fragments, not a whole schema</xsl:message>
+ </xsl:if>
+ <xsl:apply-templates select=" $theFragment_1"/>
+ </xsl:when>
+
+ <xsl:otherwise>
+ <xsl:variable name="theDocument_2" select="document( $document-uri,/ )" />
+ <xsl:variable name="theFragment_2" select="$theDocument_2/iso:*" />
+ <xsl:variable name="theContainedFragments" select="$theDocument_2/*/iso:*" />
+ <xsl:if test=" $theFragment_2/self::iso:schema or $theContainedFragments/self::iso:schema">
+ <xsl:message>Schema error: Use include to include fragments, not a whole schema</xsl:message>
+ </xsl:if>
+ <xsl:apply-templates select="$theFragment_2 | $theContainedFragments "/>
+ </xsl:otherwise>
+ </xsl:choose>
+ </xsl:template>
+
+ <!-- This is to handle the particular case of including patterns -->
+ <xsl:template match="iso:include" mode="do-all-patterns">
+ <xsl:variable name="document-uri" select="substring-before(concat(@href,'#'), '#')"/>
+ <xsl:variable name="fragment-id" select="substring-after(@href, '#')"/>
+
+ <xsl:choose>
+
+ <xsl:when test="string-length( $document-uri ) = 0 and string-length( $fragment-id ) = 0" >
+ <xsl:message>Error: Impossible URL in Schematron include</xsl:message>
+ </xsl:when>
+
+ <xsl:when test="string-length( $fragment-id ) &gt; 0">
+ <xsl:variable name="theDocument_1" select="document( $document-uri,/ )" />
+ <xsl:variable name="theFragment_1" select="$theDocument_1//iso:*[@id= $fragment-id ]" />
+ <xsl:if test=" $theFragment_1/self::iso:schema ">
+ <xsl:message>Schema error: Use include to include fragments, not a whole schema</xsl:message>
+ </xsl:if>
+ <xsl:apply-templates select=" $theFragment_1" mode="do-all-patterns"/>
+ </xsl:when>
+
+ <xsl:otherwise>
+ <!-- Import the top-level element if it is in schematron namespace,
+ or its children otherwise, to allow a simple containment mechanism. -->
+ <xsl:variable name="theDocument_2" select="document( $document-uri,/ )" />
+ <xsl:variable name="theFragment_2" select="$theDocument_2/iso:*" />
+ <xsl:variable name="theContainedFragments" select="$theDocument_2/*/iso:*" />
+ <xsl:if test=" $theFragment_2/self::iso:schema or $theContainedFragments/self::iso:schema">
+ <xsl:message>Schema error: Use include to include fragments, not a whole schema</xsl:message>
+ </xsl:if>
+ <xsl:apply-templates select="$theFragment_2 | $theContainedFragments "
+ mode="do-all-patterns" />
+ </xsl:otherwise>
+ </xsl:choose>
+ </xsl:template>
+
+ <!-- ISO LET -->
+ <xsl:template match="iso:let" >
+ <xsl:if test="ancestor::iso:schema[@queryBinding='xpath']">
+ <xsl:message>Warning: Variables should not be used with the "xpath" query language binding.</xsl:message>
+ </xsl:if>
+
+ <!-- lets at the top-level are implemented as parameters -->
+
+ <xsl:choose>
+ <xsl:when test="parent::iso:schema">
+ <!-- it is an error to have an empty param/@select because an XPath is expected -->
+ <axsl:param name="{@name}" select="{@value}">
+ <xsl:if test="string-length(@value) &gt; 0">
+ <xsl:attribute name="select"><xsl:value-of select="@value"/></xsl:attribute>
+ </xsl:if>
+ </axsl:param>
+ </xsl:when>
+ <xsl:otherwise>
+ <axsl:variable name="{@name}" select="{@value}"/>
+ </xsl:otherwise>
+ </xsl:choose>
+
+ </xsl:template>
+
+ <!-- ISO NAME -->
+ <xsl:template match="iso:name" mode="text">
+
+ <xsl:if test="@path">
+ <xsl:call-template name="process-name">
+ <xsl:with-param name="name" select="concat('name(',@path,')')"/>
+ </xsl:call-template>
+ </xsl:if>
+ <xsl:if test="not(@path)">
+ <xsl:call-template name="process-name">
+ <xsl:with-param name="name" select="'name(.)'"/>
+ </xsl:call-template>
+ </xsl:if>
+ <xsl:call-template name="IamEmpty" />
+ </xsl:template>
+
+ <!-- ISO NS -->
+ <!-- Namespace handling is XSLT is quite tricky and implementation dependent -->
+ <xsl:template match="iso:ns">
+ <xsl:call-template name="handle-namespace" />
+ </xsl:template>
+
+ <!-- This template is just to provide the API hook -->
+ <xsl:template match="iso:ns" mode="do-all-patterns" >
+ <xsl:if test="not(@uri)">
+ <xsl:message>Markup Error: no uri attribute in &lt;ns></xsl:message>
+ </xsl:if>
+ <xsl:if test="not(@prefix)">
+ <xsl:message>Markup Error: no prefix attribute in &lt;ns></xsl:message>
+ </xsl:if>
+ <xsl:call-template name="IamEmpty" />
+ <xsl:call-template name="process-ns" >
+ <xsl:with-param name="prefix" select="@prefix"/>
+ <xsl:with-param name="uri" select="@uri"/>
+ </xsl:call-template>
+ </xsl:template>
+
+ <!-- ISO P -->
+ <xsl:template match="iso:schema/iso:p " mode="do-schema-p" >
+ <xsl:call-template name="process-p">
+ <xsl:with-param name="class" select="@class"/>
+ <xsl:with-param name="icon" select="@icon"/>
+ <xsl:with-param name="id" select="@id"/>
+ <xsl:with-param name="lang" select="@xml:lang"/>
+ </xsl:call-template>
+ </xsl:template>
+ <xsl:template match="iso:pattern/iso:p " mode="do-pattern-p" >
+ <xsl:call-template name="process-p">
+ <xsl:with-param name="class" select="@class"/>
+ <xsl:with-param name="icon" select="@icon"/>
+ <xsl:with-param name="id" select="@id"/>
+ <xsl:with-param name="lang" select="@xml:lang"/>
+ </xsl:call-template>
+ </xsl:template>
+
+ <!-- Currently, iso:p in other position are not passed through to the API -->
+ <xsl:template match="iso:phase/iso:p" />
+ <xsl:template match="iso:p " priority="-1" />
+
+ <!-- ISO PATTERN -->
+ <xsl:template match="iso:pattern" mode="do-all-patterns">
+ <xsl:if test="($phase = '#ALL')
+ or (../iso:phase[@id= $phase]/iso:active[@pattern= current()/@id])">
+ <xsl:call-template name="process-pattern">
+ <!-- the following select statement assumes that
+ @id | sch:title returns node-set in document order:
+ we want the title if it is there, otherwise the @id attribute -->
+ <xsl:with-param name="name" select="(@id | iso:title )[last()]"/>
+ <xsl:with-param name="is-a" select="''"/>
+
+ <!-- "Rich" properties -->
+ <xsl:with-param name="fpi" select="@fpi"/>
+ <xsl:with-param name="icon" select="@icon"/>
+ <xsl:with-param name="id" select="@id"/>
+ <xsl:with-param name="lang" select="@xml:lang"/>
+ <xsl:with-param name="see" select="@see" />
+ <xsl:with-param name="space" select="@xml:space" />
+ </xsl:call-template>
+ <xsl:choose>
+ <xsl:when test="$select-contexts='key'">
+ <axsl:apply-templates select="key('M','M{count(preceding-sibling::*)}')" mode="M{count(preceding-sibling::*)}"/>
+ </xsl:when>
+ <xsl:when test="$select-contexts='//'">
+ <axsl:apply-templates mode="M{count(preceding-sibling::*)}">
+ <xsl:attribute name="select">
+ <xsl:text>//(</xsl:text>
+ <xsl:for-each select="iso:rule/@context">
+ <xsl:text>(</xsl:text>
+ <xsl:value-of select="."/>
+ <xsl:text>)</xsl:text>
+ <xsl:if test="position()!=last()">|</xsl:if>
+ </xsl:for-each>
+ <xsl:text>)</xsl:text>
+ <xsl:if test="$visit-text='false'">[not(self::text())]</xsl:if>
+ </xsl:attribute>
+ </axsl:apply-templates>
+ </xsl:when>
+ <xsl:otherwise>
+ <axsl:apply-templates select="/" mode="M{count(preceding-sibling::*)}"/>
+ </xsl:otherwise>
+ </xsl:choose>
+ </xsl:if>
+ </xsl:template>
+
+ <xsl:template match="iso:pattern[@abstract='true']">
+
+ <xsl:message>Schema implementation error: This schema has abstract patterns, yet they are supposed to be preprocessed out already
+ </xsl:message>
+ </xsl:template>
+
+ <!-- Here is the template for the normal case of patterns -->
+ <xsl:template match="iso:pattern[not(@abstract='true')]">
+
+ <xsl:if test="($phase = '#ALL')
+ or (../iso:phase[@id= $phase]/iso:active[@pattern= current()/@id])">
+
+ <xsl:text>&#10;&#10;</xsl:text>
+ <xsl:comment>PATTERN <xsl:value-of select="@id" /> <xsl:value-of select="iso:title" /> </xsl:comment><xsl:text>&#10;</xsl:text>
+ <xsl:apply-templates />
+
+ <!-- DPC select-contexts test -->
+ <xsl:if test="not($select-contexts)">
+ <axsl:template match="text()" priority="-1" mode="M{count(preceding-sibling::*)}">
+ <!-- strip characters -->
+ </axsl:template>
+
+ <!-- DPC introduce context-xpath variable -->
+ <axsl:template match="@*|node()"
+ priority="-2"
+ mode="M{ count(preceding-sibling::*) }">
+ <axsl:apply-templates select="{$context-xpath}" mode="M{count(preceding-sibling::*)}"/>
+ </axsl:template>
+ </xsl:if>
+ </xsl:if>
+ </xsl:template>
+
+ <!-- ISO PHASE -->
+ <xsl:template match="iso:phase" >
+ <xsl:if test="not(@id)">
+ <xsl:message>Markup Error: no id attribute in &lt;phase></xsl:message>
+ </xsl:if>
+ <xsl:apply-templates/>
+ </xsl:template>
+
+ <!-- ISO RULE -->
+ <xsl:template match="iso:rule[not(@abstract='true')] ">
+ <xsl:if test="not(@context)">
+ <xsl:message>Markup Error: no context attribute in &lt;rule></xsl:message>
+ </xsl:if>
+ <xsl:text>&#10;&#10; </xsl:text>
+ <xsl:comment>RULE <xsl:value-of select="@id" /> </xsl:comment><xsl:text>&#10;</xsl:text>
+ <xsl:if test="iso:title">
+ <xsl:comment><xsl:value-of select="iso:title" /></xsl:comment>
+ </xsl:if>
+ <!-- DPC select-contexts -->
+ <xsl:if test="$select-contexts='key'">
+ <axsl:key name="M"
+ match="{@context}"
+ use="'M{count(../preceding-sibling::*)}'"/>
+ </xsl:if>
+
+
+<!-- DPC priorities count up from 1000 not down from 4000 (templates in same priority order as before) -->
+ <axsl:template match="{@context}"
+ priority="{1000 + count(following-sibling::*)}" mode="M{count(../preceding-sibling::*)}">
+ <xsl:call-template name="process-rule">
+ <xsl:with-param name="context" select="@context"/>
+
+ <!-- "Rich" properties -->
+ <xsl:with-param name="fpi" select="@fpi"/>
+ <xsl:with-param name="icon" select="@icon"/>
+ <xsl:with-param name="id" select="@id"/>
+ <xsl:with-param name="lang" select="@xml:lang"/>
+ <xsl:with-param name="see" select="@see" />
+ <xsl:with-param name="space" select="@xml:space" />
+
+ <!-- "Linking" properties -->
+ <xsl:with-param name="role" select="@role" />
+ <xsl:with-param name="subject" select="@subject" />
+ </xsl:call-template>
+ <xsl:apply-templates/>
+ <!-- DPC introduce context-xpath and select-contexts variables -->
+ <xsl:if test="not($select-contexts)">
+ <axsl:apply-templates select="{$context-xpath}" mode="M{count(../preceding-sibling::*)}"/>
+ </xsl:if>
+ </axsl:template>
+ </xsl:template>
+
+
+ <!-- ISO ABSTRACT RULE -->
+ <xsl:template match="iso:rule[@abstract='true'] " >
+ <xsl:if test=" not(@id)">
+ <xsl:message>Markup Error: no id attribute on abstract &lt;rule></xsl:message>
+ </xsl:if>
+ <xsl:if test="@context">
+ <xsl:message>Markup Error: (2) context attribute on abstract &lt;rule></xsl:message>
+ </xsl:if>
+ </xsl:template>
+
+ <xsl:template match="iso:rule[@abstract='true']"
+ mode="extends" >
+ <xsl:if test="@context">
+ <xsl:message>Markup Error: context attribute on abstract &lt;rule></xsl:message>
+ </xsl:if>
+ <xsl:apply-templates/>
+ </xsl:template>
+
+ <!-- ISO SPAN -->
+ <xsl:template match="iso:span" mode="text">
+ <xsl:call-template name="process-span">
+ <xsl:with-param name="class" select="@class"/>
+ </xsl:call-template>
+ </xsl:template>
+
+ <!-- ISO TITLE -->
+
+ <xsl:template match="iso:schema/iso:title" priority="1">
+ <xsl:call-template name="process-schema-title" />
+ </xsl:template>
+
+
+ <xsl:template match="iso:title" >
+ <xsl:call-template name="process-title" />
+ </xsl:template>
+
+
+ <!-- ISO VALUE-OF -->
+ <xsl:template match="iso:value-of" mode="text" >
+ <xsl:if test="not(@select)">
+ <xsl:message>Markup Error: no select attribute in &lt;value-of></xsl:message>
+ </xsl:if>
+ <xsl:call-template name="IamEmpty" />
+
+ <xsl:choose>
+ <xsl:when test="@select">
+ <xsl:call-template name="process-value-of">
+ <xsl:with-param name="select" select="@select"/>
+ </xsl:call-template>
+ </xsl:when>
+ <xsl:otherwise >
+ <xsl:call-template name="process-value-of">
+ <xsl:with-param name="select" select="'.'"/>
+ </xsl:call-template>
+ </xsl:otherwise>
+ </xsl:choose>
+
+ </xsl:template>
+
+
+<!-- ============================================================== -->
+<!-- DEFAULT TEXT HANDLING -->
+<!-- ============================================================== -->
+ <xsl:template match="text()" priority="-1" mode="do-keys">
+ <!-- strip characters -->
+ </xsl:template>
+ <xsl:template match="text()" priority="-1" mode="do-all-patterns">
+ <!-- strip characters -->
+ </xsl:template>
+ <xsl:template match="text()" priority="-1" mode="do-schema-p">
+ <!-- strip characters -->
+ </xsl:template>
+ <xsl:template match="text()" priority="-1" mode="do-pattern-p">
+ <!-- strip characters -->
+ </xsl:template>
+
+ <xsl:template match="text()" priority="-1">
+ <!-- Strip characters -->
+ </xsl:template>
+
+ <xsl:template match="text()" mode="text">
+ <xsl:value-of select="."/>
+ </xsl:template>
+
+ <xsl:template match="text()" mode="inline-text">
+ <xsl:value-of select="."/>
+ </xsl:template>
+
+<!-- ============================================================== -->
+<!-- UTILITY TEMPLATES -->
+<!-- ============================================================== -->
+<xsl:template name="IamEmpty">
+ <xsl:if test="count( * )">
+ <xsl:message>
+ <xsl:text>Warning: </xsl:text>
+ <xsl:value-of select="name(.)"/>
+ <xsl:text> must not contain any child elements</xsl:text>
+ </xsl:message>
+ </xsl:if>
+</xsl:template>
+
+<xsl:template name="diagnosticsSplit">
+ <!-- Process at the current point the first of the <diagnostic> elements
+ referred to parameter str, and then recurse -->
+ <xsl:param name="str"/>
+ <xsl:variable name="start">
+ <xsl:choose>
+ <xsl:when test="contains($str,' ')">
+ <xsl:value-of select="substring-before($str,' ')"/>
+ </xsl:when>
+ <xsl:otherwise><xsl:value-of select="$str"/></xsl:otherwise>
+ </xsl:choose>
+ </xsl:variable>
+
+ <xsl:variable name="end">
+ <xsl:if test="contains($str,' ')">
+ <xsl:value-of select="substring-after($str,' ')"/>
+ </xsl:if>
+ </xsl:variable>
+
+ <!-- This works with all namespaces -->
+ <xsl:if test="not(string-length(normalize-space($start)) = 0)
+ and not(//iso:diagnostic[@id = $start])
+ and not(//sch:diagnostic[@id = $start])
+ and not(//diagnostic[@id = $start])">
+ <xsl:message>Reference error: A diagnostic "<xsl:value-of select="string($start)"
+ />" has been referenced but is not declared</xsl:message>
+ </xsl:if>
+
+ <xsl:if test="string-length(normalize-space($start)) > 0">
+ <xsl:text> </xsl:text>
+ <xsl:apply-templates
+ select="//iso:diagnostic[@id = $start ]
+ | //sch:diagnostic[@id = $start ]
+ | //diagnostic[@id= $start ]"/>
+ </xsl:if>
+
+ <xsl:if test="not($end='')">
+ <xsl:call-template name="diagnosticsSplit">
+ <xsl:with-param name="str" select="$end"/>
+ </xsl:call-template>
+ </xsl:if>
+</xsl:template>
+
+<!-- It would be nice to use this but xsl:namespace does not
+ allow a fallback -->
+<!--xsl:template name="handle-namespace" version="2.0">
+ <xsl:namespace name="{@prefix}" select="@uri">
+</xsl:template-->
+
+<xsl:template name="handle-namespace">
+ <!-- experimental code from http://eccnet.eccnet.com/pipermail/schematron-love-in/2006-June/000104.html -->
+ <!-- Handle namespaces differently for exslt systems, msxml, and default, only using XSLT1 syntax -->
+ <!-- For more info see http://fgeorges.blogspot.com/2007/01/creating-namespace-nodes-in-xslt-10.html -->
+ <xsl:choose>
+ <!-- The following code works for XSLT1 -->
+ <xsl:when test="function-available('exsl:node-set')">
+ <xsl:variable name="ns-dummy-elements">
+ <xsl:element name="{@prefix}:dummy" namespace="{@uri}"/>
+ </xsl:variable>
+ <xsl:variable name="p" select="@prefix"/>
+ <xsl:copy-of select="exsl:node-set($ns-dummy-elements)
+ /*/namespace::*[local-name()=$p]"/>
+ </xsl:when>
+
+ <!-- End XSLT1 code -->
+
+ <!-- Not tested yet
+ <xsl:when test="function-available('msxsl:node-set')">
+ <xsl:variable name="ns-dummy-elements">
+ <xsl:element name="{ $prefix }:e" namespace="{ $uri }"/>
+ </xsl:variable>
+ <xsl:copy-of select="msxsl:node-set($ns-dummy-elements)/*/namespace::*"/>
+ </xsl:when>
+ -->
+
+ <xsl:when test="@prefix = 'xsl' ">
+ <!-- Do not generate dummy attributes with the xsl: prefix, as these
+ are errors against XSLT, because we presume that the output
+ stylesheet uses the xsl prefix. In any case, there would already
+ be a namespace declaration for the XSLT namespace generated
+ automatically, presumably using "xsl:".
+ -->
+ </xsl:when>
+
+ <xsl:when test="@uri = 'http://www.w3.org/1999/XSL/Transform'">
+ <xsl:message terminate="yes">
+ <xsl:text>Using the XSLT namespace with a prefix other than "xsl" in </xsl:text>
+ <xsl:text>Schematron rules is not supported </xsl:text>
+ <xsl:text>in this processor: </xsl:text>
+ <xsl:value-of select="system-property('xsl:vendor')"/>
+ </xsl:message>
+ </xsl:when>
+
+ <xsl:otherwise>
+ <xsl:attribute name="{concat(@prefix,':dummy-for-xmlns')}" namespace="{@uri}" />
+
+ </xsl:otherwise>
+ </xsl:choose>
+
+
+</xsl:template>
+
+<!-- ============================================================== -->
+<!-- UNEXPECTED ELEMENTS -->
+<!-- ============================================================== -->
+
+ <xsl:template match="iso:*" priority="-2">
+ <xsl:message>
+ <xsl:text>Error: unrecognized element in ISO Schematron namespace: check spelling
+ and capitalization</xsl:text>
+ <xsl:value-of select="name(.)"/>
+ </xsl:message>
+ </xsl:template>
+
+
+ <!-- Swallow old namespace elements: there is an upfront test for them elsewhere -->
+ <xsl:template match="sch:*" priority="-2" />
+
+ <xsl:template match="*" priority="-3">
+ <xsl:choose>
+ <xsl:when test=" $allow-foreign = 'false' ">
+ <xsl:message>
+ <xsl:text>Warning: unrecognized element </xsl:text>
+ <xsl:value-of select="name(.)"/>
+ </xsl:message>
+ </xsl:when>
+ <xsl:otherwise>
+ <xsl:copy-of select="." />
+ </xsl:otherwise>
+ </xsl:choose>
+ </xsl:template>
+
+ <xsl:template match="iso:*" mode="text" priority="-2" />
+ <xsl:template match="*" mode="text" priority="-3">
+ <xsl:choose>
+ <xsl:when test=" $allow-foreign = 'false' ">
+ <xsl:message>
+ <xsl:text>Warning: unrecognized element </xsl:text>
+ <xsl:value-of select="name(.)"/>
+ </xsl:message>
+ </xsl:when>
+ <xsl:otherwise>
+ <xsl:copy-of select="." />
+ </xsl:otherwise>
+ </xsl:choose>
+ </xsl:template>
+
+<!-- ============================================================== -->
+<!-- DEFAULT NAMED TEMPLATES -->
+<!-- These are the actions that are performed unless overridden -->
+<!-- ============================================================== -->
+
+ <xsl:template name="process-prolog"/>
+ <!-- no params -->
+
+ <xsl:template name="process-root">
+ <xsl:param name="contents"/>
+ <xsl:param name="id" />
+ <xsl:param name="version" />
+ <xsl:param name="schemaVersion" />
+ <xsl:param name="queryBinding" />
+ <xsl:param name="title" />
+
+
+ <!-- "Rich" parameters -->
+ <xsl:param name="fpi" />
+ <xsl:param name="icon" />
+ <xsl:param name="lang" />
+ <xsl:param name="see" />
+ <xsl:param name="space" />
+
+ <xsl:copy-of select="$contents"/>
+ </xsl:template>
+
+ <xsl:template name="process-assert">
+
+ <xsl:param name="test"/>
+ <xsl:param name="diagnostics" />
+ <xsl:param name="id" />
+ <xsl:param name="flag" />
+
+ <!-- "Linkable" parameters -->
+ <xsl:param name="role"/>
+ <xsl:param name="subject"/>
+
+ <!-- "Rich" parameters -->
+ <xsl:param name="fpi" />
+ <xsl:param name="icon" />
+ <xsl:param name="lang" />
+ <xsl:param name="see" />
+ <xsl:param name="space" />
+
+
+ <xsl:call-template name="process-message">
+ <xsl:with-param name="pattern" select="$test"/>
+ <xsl:with-param name="role" select="$role"/>
+ </xsl:call-template>
+
+
+ </xsl:template>
+
+ <xsl:template name="process-report">
+ <xsl:param name="test"/>
+ <xsl:param name="diagnostics" />
+ <xsl:param name="id" />
+ <xsl:param name="flag" />
+
+ <!-- "Linkable" parameters -->
+ <xsl:param name="role"/>
+ <xsl:param name="subject"/>
+
+ <!-- "Rich" parameters -->
+ <xsl:param name="fpi" />
+ <xsl:param name="icon" />
+ <xsl:param name="lang" />
+ <xsl:param name="see" />
+ <xsl:param name="space" />
+
+ <xsl:call-template name="process-message">
+ <xsl:with-param name="pattern" select="$test"/>
+ <xsl:with-param name="role" select="$role"/>
+ </xsl:call-template>
+ </xsl:template>
+
+ <xsl:template name="process-diagnostic">
+ <xsl:param name="id" />
+
+ <!-- "Rich" parameters -->
+ <xsl:param name="fpi" />
+ <xsl:param name="icon" />
+ <xsl:param name="lang" />
+ <xsl:param name="see" />
+ <xsl:param name="space" />
+
+ <!-- We generate too much whitespace rather than risking concatenation -->
+ <axsl:text> </axsl:text>
+ <xsl:apply-templates mode="text"/>
+ <axsl:text> </axsl:text>
+ </xsl:template>
+
+ <xsl:template name="process-dir">
+ <xsl:param name="value" />
+
+ <!-- We generate too much whitespace rather than risking concatenation -->
+ <axsl:text> </axsl:text>
+ <xsl:apply-templates mode="inline-text"/>
+ <axsl:text> </axsl:text>
+ </xsl:template>
+
+ <xsl:template name="process-emph">
+ <!-- We generate too much whitespace rather than risking concatenation -->
+ <axsl:text> </axsl:text>
+ <xsl:apply-templates mode="inline-text"/>
+ <axsl:text> </axsl:text>
+ </xsl:template>
+
+ <xsl:template name="process-name">
+ <xsl:param name="name"/>
+
+ <!-- We generate too much whitespace rather than risking concatenation -->
+ <axsl:text> </axsl:text>
+ <axsl:value-of select="{$name}"/>
+ <axsl:text> </axsl:text>
+
+ </xsl:template>
+
+ <xsl:template name="process-ns" >
+ <!-- Note that process-ns is for reporting. The sch:ns elements are
+ independently used in the sch:schema template to provide namespace bindings -->
+ <xsl:param name="prefix"/>
+ <xsl:param name="uri" />
+ </xsl:template>
+
+ <xsl:template name="process-p">
+ <xsl:param name="id" />
+ <xsl:param name="class" />
+ <xsl:param name="icon" />
+ <xsl:param name="lang" />
+ </xsl:template>
+
+ <xsl:template name="process-pattern">
+ <xsl:param name="id" />
+ <xsl:param name="name" />
+ <xsl:param name="is-a" />
+
+ <!-- "Rich" parameters -->
+ <xsl:param name="fpi" />
+ <xsl:param name="icon" />
+ <xsl:param name="lang" />
+ <xsl:param name="see" />
+ <xsl:param name="space" />
+ </xsl:template>
+
+
+ <xsl:template name="process-rule">
+ <xsl:param name="context" />
+
+ <xsl:param name="id" />
+ <xsl:param name="flag" />
+
+ <!-- "Linkable" parameters -->
+ <xsl:param name="role"/>
+ <xsl:param name="subject"/>
+
+ <!-- "Rich" parameters -->
+ <xsl:param name="fpi" />
+ <xsl:param name="icon" />
+ <xsl:param name="lang" />
+ <xsl:param name="see" />
+ <xsl:param name="space" />
+ </xsl:template>
+
+ <xsl:template name="process-span" >
+ <xsl:param name="class" />
+
+ <!-- We generate too much whitespace rather than risking concatenation -->
+ <axsl:text> </axsl:text>
+ <xsl:apply-templates mode="inline-text"/>
+ <axsl:text> </axsl:text>
+ </xsl:template>
+
+ <xsl:template name="process-title" >
+ <xsl:param name="class" />
+ <xsl:call-template name="process-p">
+ <xsl:with-param name="class">title</xsl:with-param>
+ </xsl:call-template>
+ </xsl:template>
+
+ <xsl:template name="process-schema-title" >
+ <xsl:param name="class" />
+ <xsl:call-template name="process-title">
+ <xsl:with-param name="class">schema-title</xsl:with-param>
+ </xsl:call-template>
+ </xsl:template>
+
+ <xsl:template name="process-value-of">
+ <xsl:param name="select"/>
+
+ <!-- We generate too much whitespace rather than risking concatenation -->
+ <axsl:text> </axsl:text>
+ <axsl:value-of select="{$select}"/>
+ <axsl:text> </axsl:text>
+ </xsl:template>
+
+ <!-- default output action: the simplest customization is to just override this -->
+ <xsl:template name="process-message">
+ <xsl:param name="pattern" />
+ <xsl:param name="role" />
+
+ <xsl:apply-templates mode="text"/>
+ <xsl:if test=" $message-newline = 'true'" >
+ <axsl:value-of select="string('&#10;')"/>
+ </xsl:if>
+
+ </xsl:template>
+</xsl:stylesheet>
+
+
+
diff --git a/src/lxml/isoschematron/resources/xsl/iso-schematron-xslt1/iso_svrl_for_xslt1.xsl b/src/lxml/isoschematron/resources/xsl/iso-schematron-xslt1/iso_svrl_for_xslt1.xsl
new file mode 100644
index 00000000..dae74ff6
--- /dev/null
+++ b/src/lxml/isoschematron/resources/xsl/iso-schematron-xslt1/iso_svrl_for_xslt1.xsl
@@ -0,0 +1,588 @@
+<?xml version="1.0" ?>
+<!--
+ ISO_SVRL.xsl
+
+ Implementation of Schematron Validation Report Language from ISO Schematron
+ ISO/IEC 19757 Document Schema Definition Languages (DSDL)
+ Part 3: Rule-based validation Schematron
+ Annex D: Schematron Validation Report Language
+
+ This ISO Standard is available free as a Publicly Available Specification in PDF from ISO.
+ Also see www.schematron.com for drafts and other information.
+
+ This implementation of SVRL is designed to run with the "Skeleton" implementation
+ of Schematron which Oliver Becker devised. The skeleton code provides a
+ Schematron implementation but with named templates for handling all output;
+ the skeleton provides basic templates for output using this API, but client
+ validators can be written to import the skeleton and override the default output
+ templates as required. (In order to understand this, you must understand that
+ a named template such as "process-assert" in this XSLT stylesheet overrides and
+ replaces any template with the same name in the imported skeleton XSLT file.)
+
+ The other important thing to understand in this code is that there are different
+ versions of the Schematron skeleton. These track the development of Schematron through
+ Schematron 1.5, Schematron 1.6 and now ISO Schematron. One only skeleton must be
+ imported. The code has templates for the different skeletons commented out for
+ convenience. ISO Schematron has a different namespace than Schematron 1.5 and 1.6;
+ so the ISO Schematron skeleton has been written itself with an optional import
+ statement to in turn import the Schematron 1.6 skeleton. This will allow you to
+ validate with schemas from either namespace.
+
+
+ History:
+ 2009-03-18
+ * Fix atrribute with space "see " which generates wrong name in some processors
+ 2008-08-11
+ * RJ Fix attribute/@select which saxon allows in XSLT 1
+ 2008-08-07
+ * RJ Add output-encoding attribute to specify final encoding to use
+ * Alter allow-foreign functionality so that Schematron span, emph and dir elements make
+ it to the output, for better formatting and because span can be used to mark up
+ semantically interesting information embedded in diagnostics, which reduces the
+ need to extend SVRL itself
+ * Diagnostic-reference had an invalid attribute @id that duplicated @diagnostic: removed
+ 2008-08-06
+ * RJ Fix invalid output: svrl:diagnostic-reference is not contained in an svrl:text
+ * Output comment to SVRL file giving filename if available (from command-line parameter)
+ 2008-08-04
+ * RJ move sch: prefix to schold: prefix to prevent confusion (we want people to
+ be able to switch from old namespace to new namespace without changing the
+ sch: prefix, so it is better to keep that prefix completely out of the XSLT)
+ * Extra signature fixes (PH)
+ 2008-08-03
+ * Repair missing class parameter on process-p
+ 2008-07-31
+ * Update skeleton names
+ 2007-04-03
+ * Add option generate-fired-rule (RG)
+ 2007-02-07
+ * Prefer true|false for parameters. But allow yes|no on some old for compatability
+ * DP Diagnostics output to svrl:text. Diagnosis put out after assertion text.
+ * Removed non-SVRL elements and attributes: better handled as an extra layer that invokes this one
+ * Add more formal parameters
+ * Correct confusion between $schemaVersion and $queryBinding
+ * Indent
+ * Validate against RNC schemas for XSLT 1 and 2 (with regex tests removed)
+ * Validate output with UniversalTest.sch against RNC schema for ISO SVRL
+
+ 2007-02-01
+ * DP. Update formal parameters of overriding named templates to handle more attributes.
+ * DP. Refactor handling of rich and linkable parameters to a named template.
+
+ 2007-01-22
+ * DP change svrl:ns to svrl:ns-in-attribute-value
+ * Change default when no queryBinding from "unknown" to "xslt"
+
+ 2007-01-18:
+ * Improve documentation
+ * KH Add command-line options to generate paths or not
+ * Use axsl:attribute rather than xsl:attribute to shut XSLT2 up
+ * Add extra command-line options to pass to the iso_schematron_skeleton
+
+ 2006-12-01: iso_svrl.xsl Rick Jelliffe,
+ * update namespace,
+ * update phase handling,
+ * add flag param to process-assert and process-report & @ flag on output
+
+ 2001: Conformance1-5.xsl Rick Jelliffe,
+ * Created, using the skeleton code contributed by Oliver Becker
+-->
+<!--
+ Derived from Conformance1-5.xsl.
+
+ Copyright (c) 2001, 2006 Rick Jelliffe and Academia Sinica Computing Center, Taiwan
+
+ This software is provided 'as-is', without any express or implied warranty.
+ In no event will the authors be held liable for any damages arising from
+ the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it freely,
+ subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not claim
+ that you wrote the original software. If you use this software in a product,
+ an acknowledgment in the product documentation would be appreciated but is
+ not required.
+
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+
+ 3. This notice may not be removed or altered from any source distribution.
+-->
+
+<!-- Ideas nabbed from schematrons by Francis N., Miloslav N. and David C. -->
+
+<!-- The command-line parameters are:
+ phase NMTOKEN | "#ALL" (default) Select the phase for validation
+ allow-foreign "true" | "false" (default) Pass non-Schematron elements and rich markup to the generated stylesheet
+ diagnose= true | false|yes|no Add the diagnostics to the assertion test in reports (yes|no are obsolete)
+ generate-paths=true|false|yes|no generate the @location attribute with XPaths (yes|no are obsolete)
+ sch.exslt.imports semi-colon delimited string of filenames for some EXSLT implementations
+ optimize "visit-no-attributes" Use only when the schema has no attributes as the context nodes
+ generate-fired-rule "true"(default) | "false" Generate fired-rule elements
+
+-->
+
+<xsl:stylesheet
+ version="1.0"
+ xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
+ xmlns:xs="http://www.w3.org/2001/XMLSchema"
+ xmlns:axsl="http://www.w3.org/1999/XSL/TransformAlias"
+ xmlns:schold="http://www.ascc.net/xml/schematron"
+ xmlns:iso="http://purl.oclc.org/dsdl/schematron"
+ xmlns:svrl="http://purl.oclc.org/dsdl/svrl"
+>
+
+<!-- Select the import statement and adjust the path as
+ necessary for your system.
+ If not XSLT2 then also remove svrl:active-pattern/@document="{document-uri()}" from process-pattern()
+-->
+<!--
+<xsl:import href="iso_schematron_skeleton_for_saxon.xsl"/>
+-->
+
+<xsl:import href="iso_schematron_skeleton_for_xslt1.xsl"/>
+ <!--
+<xsl:import href="iso_schematron_skeleton.xsl"/>
+<xsl:import href="skeleton1-5.xsl"/>
+<xsl:import href="skeleton1-6.xsl"/>
+-->
+
+<xsl:param name="diagnose" >true</xsl:param>
+<xsl:param name="phase" >
+ <xsl:choose>
+ <!-- Handle Schematron 1.5 and 1.6 phases -->
+ <xsl:when test="//schold:schema/@defaultPhase">
+ <xsl:value-of select="//schold:schema/@defaultPhase"/>
+ </xsl:when>
+ <!-- Handle ISO Schematron phases -->
+ <xsl:when test="//iso:schema/@defaultPhase">
+ <xsl:value-of select="//iso:schema/@defaultPhase"/>
+ </xsl:when>
+ <xsl:otherwise>#ALL</xsl:otherwise>
+ </xsl:choose>
+</xsl:param>
+<xsl:param name="allow-foreign" >false</xsl:param>
+<xsl:param name="generate-paths" >true</xsl:param>
+<xsl:param name="generate-fired-rule" >true</xsl:param>
+<xsl:param name="optimize"/>
+
+<xsl:param name="output-encoding" ></xsl:param>
+
+<!-- e.g. saxon file.xml file.xsl "sch.exslt.imports=.../string.xsl;.../math.xsl" -->
+<xsl:param name="sch.exslt.imports" />
+
+
+
+<!-- Experimental: If this file called, then must be generating svrl -->
+<xsl:variable name="svrlTest" select="true()" />
+
+
+
+<!-- ================================================================ -->
+
+<xsl:template name="process-prolog">
+ <axsl:output method="xml" omit-xml-declaration="no" standalone="yes"
+ indent="yes">
+ <xsl:if test=" string-length($output-encoding) &gt; 0">
+ <xsl:attribute name="encoding"><xsl:value-of select=" $output-encoding" /></xsl:attribute>
+ </xsl:if>
+ </axsl:output>
+
+</xsl:template>
+
+<!-- Overrides skeleton.xsl -->
+<xsl:template name="process-root">
+ <xsl:param name="title"/>
+ <xsl:param name="contents" />
+ <xsl:param name="queryBinding" >xslt1</xsl:param>
+ <xsl:param name="schemaVersion" />
+ <xsl:param name="id" />
+ <xsl:param name="version"/>
+ <!-- "Rich" parameters -->
+ <xsl:param name="fpi" />
+ <xsl:param name="icon" />
+ <xsl:param name="lang" />
+ <xsl:param name="see" />
+ <xsl:param name="space" />
+
+ <svrl:schematron-output title="{$title}" schemaVersion="{$schemaVersion}" >
+ <xsl:if test=" string-length( normalize-space( $phase )) &gt; 0 and
+ not( normalize-space( $phase ) = '#ALL') ">
+ <axsl:attribute name="phase">
+ <xsl:value-of select=" $phase " />
+ </axsl:attribute>
+ </xsl:if>
+ <xsl:if test=" $allow-foreign = 'true'">
+ </xsl:if>
+ <xsl:if test=" $allow-foreign = 'true'">
+
+ <xsl:call-template name='richParms'>
+ <xsl:with-param name="fpi" select="$fpi" />
+ <xsl:with-param name="icon" select="$icon"/>
+ <xsl:with-param name="lang" select="$lang"/>
+ <xsl:with-param name="see" select="$see" />
+ <xsl:with-param name="space" select="$space" />
+ </xsl:call-template>
+ </xsl:if>
+
+ <axsl:comment><axsl:value-of select="$archiveDirParameter"/> &#xA0;
+ <axsl:value-of select="$archiveNameParameter"/> &#xA0;
+ <axsl:value-of select="$fileNameParameter"/> &#xA0;
+ <axsl:value-of select="$fileDirParameter"/></axsl:comment>
+
+
+ <xsl:apply-templates mode="do-schema-p" />
+ <xsl:copy-of select="$contents" />
+ </svrl:schematron-output>
+</xsl:template>
+
+
+<xsl:template name="process-assert">
+ <xsl:param name="test"/>
+ <xsl:param name="diagnostics" />
+ <xsl:param name="id" />
+ <xsl:param name="flag" />
+ <!-- "Linkable" parameters -->
+ <xsl:param name="role"/>
+ <xsl:param name="subject"/>
+ <!-- "Rich" parameters -->
+ <xsl:param name="fpi" />
+ <xsl:param name="icon" />
+ <xsl:param name="lang" />
+ <xsl:param name="see" />
+ <xsl:param name="space" />
+ <svrl:failed-assert test="{$test}" >
+ <xsl:if test="string-length( $id ) &gt; 0">
+ <axsl:attribute name="id">
+ <xsl:value-of select=" $id " />
+ </axsl:attribute>
+ </xsl:if>
+ <xsl:if test=" string-length( $flag ) &gt; 0">
+ <axsl:attribute name="flag">
+ <xsl:value-of select=" $flag " />
+ </axsl:attribute>
+ </xsl:if>
+ <!-- Process rich attributes. -->
+ <xsl:call-template name="richParms">
+ <xsl:with-param name="fpi" select="$fpi"/>
+ <xsl:with-param name="icon" select="$icon"/>
+ <xsl:with-param name="lang" select="$lang"/>
+ <xsl:with-param name="see" select="$see" />
+ <xsl:with-param name="space" select="$space" />
+ </xsl:call-template>
+ <xsl:call-template name='linkableParms'>
+ <xsl:with-param name="role" select="$role" />
+ <xsl:with-param name="subject" select="$subject"/>
+ </xsl:call-template>
+ <xsl:if test=" $generate-paths = 'true' or $generate-paths= 'yes' ">
+ <!-- true/false is the new way -->
+ <axsl:attribute name="location">
+ <axsl:apply-templates select="." mode="schematron-get-full-path"/>
+ </axsl:attribute>
+ </xsl:if>
+
+ <svrl:text>
+ <xsl:apply-templates mode="text" />
+
+ </svrl:text>
+ <xsl:if test="$diagnose = 'yes' or $diagnose= 'true' ">
+ <!-- true/false is the new way -->
+ <xsl:call-template name="diagnosticsSplit">
+ <xsl:with-param name="str" select="$diagnostics"/>
+ </xsl:call-template>
+ </xsl:if>
+ </svrl:failed-assert>
+</xsl:template>
+
+<xsl:template name="process-report">
+ <xsl:param name="id"/>
+ <xsl:param name="test"/>
+ <xsl:param name="diagnostics"/>
+ <xsl:param name="flag" />
+ <!-- "Linkable" parameters -->
+ <xsl:param name="role"/>
+ <xsl:param name="subject"/>
+ <!-- "Rich" parameters -->
+ <xsl:param name="fpi" />
+ <xsl:param name="icon" />
+ <xsl:param name="lang" />
+ <xsl:param name="see" />
+ <xsl:param name="space" />
+ <svrl:successful-report test="{$test}" >
+ <xsl:if test=" string-length( $id ) &gt; 0">
+ <axsl:attribute name="id">
+ <xsl:value-of select=" $id " />
+ </axsl:attribute>
+ </xsl:if>
+ <xsl:if test=" string-length( $flag ) &gt; 0">
+ <axsl:attribute name="flag">
+ <xsl:value-of select=" $flag " />
+ </axsl:attribute>
+ </xsl:if>
+
+ <!-- Process rich attributes. -->
+ <xsl:call-template name="richParms">
+ <xsl:with-param name="fpi" select="$fpi"/>
+ <xsl:with-param name="icon" select="$icon"/>
+ <xsl:with-param name="lang" select="$lang"/>
+ <xsl:with-param name="see" select="$see" />
+ <xsl:with-param name="space" select="$space" />
+ </xsl:call-template>
+ <xsl:call-template name='linkableParms'>
+ <xsl:with-param name="role" select="$role" />
+ <xsl:with-param name="subject" select="$subject"/>
+ </xsl:call-template>
+ <xsl:if test=" $generate-paths = 'yes' or $generate-paths = 'true' ">
+ <!-- true/false is the new way -->
+ <axsl:attribute name="location">
+ <axsl:apply-templates select="." mode="schematron-get-full-path"/>
+ </axsl:attribute>
+ </xsl:if>
+
+ <svrl:text>
+ <xsl:apply-templates mode="text" />
+
+ </svrl:text>
+ <xsl:if test="$diagnose = 'yes' or $diagnose='true' ">
+ <!-- true/false is the new way -->
+ <xsl:call-template name="diagnosticsSplit">
+ <xsl:with-param name="str" select="$diagnostics"/>
+ </xsl:call-template>
+ </xsl:if>
+ </svrl:successful-report>
+</xsl:template>
+
+
+ <!-- Overrides skeleton -->
+ <xsl:template name="process-dir" >
+ <xsl:param name="value" />
+ <xsl:choose>
+ <xsl:when test=" $allow-foreign = 'true'">
+ <xsl:copy-of select="."/>
+ </xsl:when>
+
+ <xsl:otherwise>
+ <!-- We generate too much whitespace rather than risking concatenation -->
+ <axsl:text> </axsl:text>
+ <xsl:apply-templates mode="inline-text"/>
+ <axsl:text> </axsl:text>
+ </xsl:otherwise>
+ </xsl:choose>
+ </xsl:template>
+
+<xsl:template name="process-diagnostic">
+ <xsl:param name="id"/>
+ <!-- Rich parameters -->
+ <xsl:param name="fpi" />
+ <xsl:param name="icon" />
+ <xsl:param name="lang" />
+ <xsl:param name="see" />
+ <xsl:param name="space" />
+ <svrl:diagnostic-reference diagnostic="{$id}" >
+
+ <xsl:call-template name="richParms">
+ <xsl:with-param name="fpi" select="$fpi"/>
+ <xsl:with-param name="icon" select="$icon"/>
+ <xsl:with-param name="lang" select="$lang"/>
+ <xsl:with-param name="see" select="$see" />
+ <xsl:with-param name="space" select="$space" />
+ </xsl:call-template>
+<xsl:text>
+</xsl:text>
+
+ <xsl:apply-templates mode="text"/>
+
+ </svrl:diagnostic-reference>
+</xsl:template>
+
+
+ <!-- Overrides skeleton -->
+ <xsl:template name="process-emph" >
+ <xsl:param name="class" />
+ <xsl:choose>
+ <xsl:when test=" $allow-foreign = 'true'">
+ <xsl:copy-of select="."/>
+ </xsl:when>
+ <xsl:otherwise>
+ <!-- We generate too much whitespace rather than risking concatenation -->
+ <axsl:text> </axsl:text>
+ <xsl:apply-templates mode="inline-text"/>
+ <axsl:text> </axsl:text>
+ </xsl:otherwise>
+ </xsl:choose>
+ </xsl:template>
+
+<xsl:template name="process-rule">
+ <xsl:param name="id"/>
+ <xsl:param name="context"/>
+ <xsl:param name="flag"/>
+ <!-- "Linkable" parameters -->
+ <xsl:param name="role"/>
+ <xsl:param name="subject"/>
+ <!-- "Rich" parameters -->
+ <xsl:param name="fpi" />
+ <xsl:param name="icon" />
+ <xsl:param name="lang" />
+ <xsl:param name="see" />
+ <xsl:param name="space" />
+ <xsl:if test=" $generate-fired-rule = 'true'">
+ <svrl:fired-rule context="{$context}" >
+ <!-- Process rich attributes. -->
+ <xsl:call-template name="richParms">
+ <xsl:with-param name="fpi" select="$fpi"/>
+ <xsl:with-param name="icon" select="$icon"/>
+ <xsl:with-param name="lang" select="$lang"/>
+ <xsl:with-param name="see" select="$see" />
+ <xsl:with-param name="space" select="$space" />
+ </xsl:call-template>
+ <xsl:if test=" string( $id )">
+ <xsl:attribute name="id">
+ <xsl:value-of select=" $id " />
+ </xsl:attribute>
+ </xsl:if>
+ <xsl:if test=" string-length( $role ) &gt; 0">
+ <xsl:attribute name="role">
+ <xsl:value-of select=" $role " />
+ </xsl:attribute>
+ </xsl:if>
+ </svrl:fired-rule>
+</xsl:if>
+</xsl:template>
+
+<xsl:template name="process-ns">
+ <xsl:param name="prefix"/>
+ <xsl:param name="uri"/>
+ <svrl:ns-prefix-in-attribute-values uri="{$uri}" prefix="{$prefix}" />
+</xsl:template>
+
+<xsl:template name="process-p">
+ <xsl:param name="icon"/>
+ <xsl:param name="class"/>
+ <xsl:param name="id"/>
+ <xsl:param name="lang"/>
+
+ <svrl:text>
+ <xsl:apply-templates mode="text"/>
+ </svrl:text>
+</xsl:template>
+
+<xsl:template name="process-pattern">
+ <xsl:param name="name"/>
+ <xsl:param name="id"/>
+ <xsl:param name="is-a"/>
+
+ <!-- "Rich" parameters -->
+ <xsl:param name="fpi" />
+ <xsl:param name="icon" />
+ <xsl:param name="lang" />
+ <xsl:param name="see" />
+ <xsl:param name="space" />
+ <svrl:active-pattern >
+ <xsl:if test=" string( $id )">
+ <axsl:attribute name="id">
+ <xsl:value-of select=" $id " />
+ </axsl:attribute>
+ </xsl:if>
+ <xsl:if test=" string( $name )">
+ <axsl:attribute name="name">
+ <xsl:value-of select=" $name " />
+ </axsl:attribute>
+ </xsl:if>
+
+ <xsl:call-template name='richParms'>
+ <xsl:with-param name="fpi" select="$fpi"/>
+ <xsl:with-param name="icon" select="$icon"/>
+ <xsl:with-param name="lang" select="$lang"/>
+ <xsl:with-param name="see" select="$see" />
+ <xsl:with-param name="space" select="$space" />
+ </xsl:call-template>
+
+ <!-- ?? report that this screws up iso:title processing -->
+ <xsl:apply-templates mode="do-pattern-p"/>
+ <!-- ?? Seems that this apply-templates is never triggered DP -->
+ <axsl:apply-templates />
+ </svrl:active-pattern>
+</xsl:template>
+
+<!-- Overrides skeleton -->
+<xsl:template name="process-message" >
+ <xsl:param name="pattern"/>
+ <xsl:param name="role"/>
+</xsl:template>
+
+
+ <!-- Overrides skeleton -->
+ <xsl:template name="process-span" >
+ <xsl:param name="class" />
+ <xsl:choose>
+ <xsl:when test=" $allow-foreign = 'true'">
+ <xsl:copy-of select="."/>
+ </xsl:when>
+ <xsl:otherwise>
+ <!-- We generate too much whitespace rather than risking concatenation -->
+ <axsl:text> </axsl:text>
+ <xsl:apply-templates mode="inline-text"/>
+ <axsl:text> </axsl:text>
+ </xsl:otherwise>
+ </xsl:choose>
+ </xsl:template>
+
+<!-- =========================================================================== -->
+<!-- processing rich parameters. -->
+<xsl:template name='richParms'>
+ <!-- "Rich" parameters -->
+ <xsl:param name="fpi" />
+ <xsl:param name="icon" />
+ <xsl:param name="lang" />
+ <xsl:param name="see" />
+ <xsl:param name="space" />
+ <!-- Process rich attributes. -->
+ <xsl:if test=" $allow-foreign = 'true'">
+ <xsl:if test="string($fpi)">
+ <axsl:attribute name="fpi">
+ <xsl:value-of select="$fpi"/>
+ </axsl:attribute>
+ </xsl:if>
+ <xsl:if test="string($icon)">
+ <axsl:attribute name="icon">
+ <xsl:value-of select="$icon"/>
+ </axsl:attribute>
+ </xsl:if>
+ <xsl:if test="string($see)">
+ <axsl:attribute name="see">
+ <xsl:value-of select="$see"/>
+ </axsl:attribute>
+ </xsl:if>
+ </xsl:if>
+ <xsl:if test="string($space)">
+ <axsl:attribute name="xml:space">
+ <xsl:value-of select="$space"/>
+ </axsl:attribute>
+ </xsl:if>
+ <xsl:if test="string($lang)">
+ <axsl:attribute name="xml:lang">
+ <xsl:value-of select="$lang"/>
+ </axsl:attribute>
+ </xsl:if>
+</xsl:template>
+
+<!-- processing linkable parameters. -->
+<xsl:template name='linkableParms'>
+ <xsl:param name="role"/>
+ <xsl:param name="subject"/>
+
+ <!-- ISO SVRL has a role attribute to match the Schematron role attribute -->
+ <xsl:if test=" string($role )">
+ <axsl:attribute name="role">
+ <xsl:value-of select=" $role " />
+ </axsl:attribute>
+ </xsl:if>
+ <!-- ISO SVRL does not have a subject attribute to match the Schematron subject attribute.
+ Instead, the Schematron subject attribute is folded into the location attribute -->
+</xsl:template>
+
+
+</xsl:stylesheet>
+
diff --git a/src/lxml/isoschematron/resources/xsl/iso-schematron-xslt1/readme.txt b/src/lxml/isoschematron/resources/xsl/iso-schematron-xslt1/readme.txt
new file mode 100644
index 00000000..d9f68c5a
--- /dev/null
+++ b/src/lxml/isoschematron/resources/xsl/iso-schematron-xslt1/readme.txt
@@ -0,0 +1,83 @@
+ISO SCHEMATRON 2009
+
+XSLT implementation by Rick Jelliffe with assistance from members of Schematron-love-in maillist.
+
+2009-03-18
+
+Two distributions are available. One is for XSLT1 engines.
+The other is for XSLT2 engines, such as SAXON 9.
+
+
+This version of Schematron splits the process into a pipeline of several different XSLT stages.
+
+1) First, preprocess your Schematron schema with iso_dsdl_include.xsl.
+This is a macro processor to assemble the schema from various parts.
+If your schema is not in separate parts, you can skip this stage.
+
+2) Second, preprocess the output from stage 1 with iso_abstract_expand.xsl.
+This is a macro processor to convert abstract patterns to real patterns.
+If your schema does not use abstract patterns, you can skip this
+stage.
+
+3) Third, compile the Schematron schema into an XSLT script.
+This will typically use iso_svrl_for_xslt1.xsl or iso_svrl_for_xslt2.xsl
+(which in turn invoke iso_schematron_skeleton_for_xslt1.xsl or iso_schematron_skeleton_for_saxon.xsl)
+However, other "meta-styleseets" are also in common use; the principle of operation is the same.
+If your schema uses Schematron phases, supply these as command line/invocation parameters
+to this process.
+
+4) Fourth, run the script generated by stage 3 against the document being validated.
+If you are using the SVRL script, then the output of validation will be an XML document.
+If your schema uses Schematron parameters, supply these as command line/invocation parameters
+to this process.
+
+
+The XSLT2 distribution also features several next generation features,
+such as validating multiple documents. See the source code for details.
+
+Schematron assertions can be written in any language, of course; the file
+sch-messages-en.xhtml contains the diagnostics messages from the XSLT2 skeleton
+in English, and this can be used as template to localize the skeleton's
+error messages. Note that typically programming errors in Schematron are XPath
+errors, which requires localized messages from the XSLT engine.
+
+ANT
+---
+To give an example of how to process a document, here is a sample ANT task.
+
+<target name="schematron-compile-test" >
+
+ <!-- expand inclusions -->
+ <xslt basedir="test/schematron"
+ style="iso_dsdl_include.xsl" in="test.sch" out="test1.sch">
+ <classpath>
+ <pathelement location="${lib.dir}/saxon9.jar"/>
+ </classpath>
+ </xslt>
+
+ <!-- expand abstract patterns -->
+ <xslt basedir="test/schematron"
+ style="iso_abstract_expand.xsl" in="test1.sch" out="test2.sch">
+ <classpath>
+ <pathelement location="${lib.dir}/saxon9.jar"/>
+ </classpath>
+ </xslt>
+
+
+
+ <!-- compile it -->
+ <xslt basedir="test/schematron"
+ style="iso_svrl_for_xslt2.xsl" in="test2.sch" out="test.xsl">
+ <classpath>
+ <pathelement location="${lib.dir}/saxon9.jar"/>
+ </classpath>
+ </xslt>
+
+ <!-- validate -->
+ <xslt basedir="test/schematron"
+ style="test.xsl" in="instance.xml" out="instance.svrlt">
+ <classpath>
+ <pathelement location="${lib.dir}/saxon9.jar"/>
+ </classpath>
+ </xslt>
+ </target> \ No newline at end of file