2 ms·
XML specified with a mix of RelaxNG and Schematron is a really nice pairing. Both are interesting and a little different to the usual schema languages. RelaxNG
by emmanueloga_ 6y ago
XML specified with a mix of RelaxNG and Schematron is a really nice pairing. Both are interesting and a little different to the usual schema languages.
RelaxNG is like "regular expressions for trees". It has a compact syntax like this:
start = element library {
element book {
attribute title { text },
element page { text }+
}
}
.. so books in this library (root element) should have a title attribute and one or more pages. There's a (pretty geeky [] :-p) description of the algorithm here [1] (: Brzozowski derivatives + Haskell!).
Schematron is another schema language that allows specifying constraints as a series of pattern rules:
<schema xmlns="http://purl.oclc.org/dsdl/schematron">
<pattern>
<rule context="book">
<assert test="let $b := .[starts-with(@title, 'A')] return $b/page/count() >= 100">
Books whose title starts with "A" must have 100 or more pages.
</assert>
</rule>
</pattern>
</schema>
So it allows specifying constraints that would be too tedious or impossible with RelaxNG, and allows keeping the RelaxNG grammar simple.
The test on the Schematron "assert" element in the example uses "let expressions" [2], one of many additions that makes XPath and XSLT 3.0 feel a lot like any other modern functional programming language (other features: higher order functions, maps/arrays/JSON support, and more). This presentation [3] shows a few more 3.0 features.
If lisp is for lists, then XSLT definitely is for trees! I suspect as people start forgetting the baggage of SOAP and XSLT 1.0, the language is going to become more and more popular since it is so useful. BTW, there's now a JavaScript implementation that runs on node and the browser too [4].
1: https://relaxng.org/jclark/derivative.html https://relaxng.org/jclark/derivative.html
2: https://www.w3.org/TR/xpath-30/#id-let-expressions https://www.w3.org/TR/xpath-30/#id-let-expressions
3: https://www.kosek.cz/xml/2019xmlss/Kosek_XSLT4DailyCoding.pdf https://www.kosek.cz/xml/2019xmlss/Kosek_XSLT4DailyCoding.pd...
4: https://www.npmjs.com/package/saxon-js https://www.npmjs.com/package/saxon-js