Repository navigation
Streamability
The module ph-schematron-streamability tells upfront, per rule, whether a Schematron can be validated while the instance document is read as a stream, and how much of the document a validator must keep in memory.
It only reports; there is no streaming validation mode yet.
The analysis is a property of the schema, not of an engine or an XSLT processor, so the report holds for every engine.
It uses the streamability analysis of phoxtrot (XSLT 3.0 section 19, with a burst mode) and needs only phoxtrot-xpath, not the phoxtrot XSLT engine and not Saxon.
Saxon-HE has no streamability analysis (streaming is a Saxon-EE feature).
| Class | ID | The rule needs | Streaming |
|---|---|---|---|
| Motionless | motionless |
the context node, its attributes, its ancestors and their attributes | one pass, constant memory |
| Burst | burst |
only the subtree of the context node | one pass; the subtree of each matched node is buffered, checked and dropped (memory = the largest matched subtree) |
| Non-local | non-local |
anything outside the subtree: the root, //, preceding/following, key () or id () over the instance, a global sch:let computed from the instance |
two passes or the whole tree |
A rule has the class of its worst expression, a pattern the class of its worst rule, and the schema the class of its worst pattern or global expression.
Examples, with cac:InvoiceLine as rule context:
| Test | Class | Reason |
|---|---|---|
@id = 'x' |
motionless | |
ancestor::cac:Invoice/@version |
motionless | |
/cac:Invoice/@version |
motionless | |
cbc:A = 'x' or cbc:B = 'y' |
burst | expression operator or |
sum (cac:Line/cbc:Amount) = cbc:Total |
burst | expression comparison |
../cbc:ID |
non-local | axis step parent::node() |
//cbc:ID |
non-local | axis step // |
key ('k', @id) |
non-local | function key#2 |
- The schema is preprocessed first (includes, abstract patterns and rules,
extends). - The rule context is an XSLT pattern: motionless if it can be matched on the streamed node alone, burst if a predicate reads only the subtree of the node (
cac:InvoiceLine[cbc:Quantity < 0]), else non-local. - The
testof eachsch:assertandsch:report, thesch:value-ofandsch:nameof their messages and of the diagnostics they reference, and the rule'ssch:lets, with the rule context as context and as the validator evaluates them (effective boolean value of a test, atomised value of asch:value-of). - A rule's
sch:lets are analysed where they are used: an expression is analysed together with thesch:lets it uses (directly or through another one). Computing asch:letof the parent (..) is motionless; navigating from it is non-local. - The
sch:lets of the schema, the phases and the patterns are computed once with the document node as context. One that reads the instance needs a first pass and is non-local; a rule may compare its value, but navigating from its nodes is non-local. One that does not read the instance (a literal, a value from another document viadocument ()) is motionless. -
xsl:functionelements of the schema are only known by theirstreamabilityattribute (XSLT 3.0 section 19.8.5). A call of a function without it, and of any extension function, is non-local.
The analysis fails closed. These are always non-local:
-
sch:group,pattern/@documentsandrule/@visit-each(reported as "unsupported") - a
sch:letwith element content instead of avalueattribute - an expression with a static error (the reason names the error)
Add the following to your pom.xml, replacing x.y.z with the latest version number:
<dependency>
<groupId>com.helger.schematron</groupId>
<artifactId>ph-schematron-streamability</artifactId>
<version>x.y.z</version>
</dependency>SchematronStreamabilityReport aReport = SchematronStreamabilityAnalyzer.analyze (new FileSystemResource ("rules.sch"));
// e.g. "burst: 3 patterns, 120 rules (100 motionless, 20 burst, 0 non-local), 1 global expression"
System.out.println (aReport.getSummaryText ());
// One line per expression that is not motionless, with pattern, rule, expression, class and reason
for (String sFinding : aReport.getAllFindingTexts ())
System.out.println (sFinding);SchematronStreamabilityAnalyzer.analyze also takes a PSSchema.
The report (SchematronStreamabilityReport) has the global expressions (getAllGlobalExpressions ()) and the patterns (getAllPatterns (), each a PatternStreamability with its RuleStreamabilitys).
Every analysed expression is a StreamabilityExpression with its type (EStreamabilityExpressionType), label (the sch:let name or the assertion ID), expression, class (EStreamabilityClass) and reason.
- Maven: the goal
streamability- see Maven plugin - Ant: the task
SchematronStreamability- see ANT tasks
Both log the summary and the findings, and fail if the schema is worse than the configured maximumClass.
On Twitter: Follow @philiphelger
Donation link: https://paypal.me/PhilipHelger
It is appreciated if you star the GitHub project if you like it.