Schematron / schematron-enhancement-proposals

This repository collects proposals to enhance Schematron beyond the ISO specification
9 stars 0 forks source link

Enhance sch:let to support functions, accumuators and keys #45

Open rjelliffe opened 2 years ago

rjelliffe commented 2 years ago

This is a proposal to enhance sch:let so that it can be used for

This current email only looks at two issues:

A desirable side-effect might be that, with viable "Schematron-y" ways to do functions etc, XSLT namespace elements could be disallowed in Schematron schemas (unless pulled in as an external library.)

Background

During the initial standardization, we discussed whether Schematron should have functions. Because it was not clear then that XSLT would be as common as XPath implementations or what was happening with data typing, we decided to keep things minimal, and to allow piggybacking constrained by the QLB.

Providing them was prudent, practical and generous for a new standard for a juvenile language, especially one aiming to be as minimal as possible. However,perhaps we should now be looking at how to evolve Schematron to have denotative support for them: it may low-hanging fruit!

The context of this is the discussions on libraries and which XSLT elements should be allowed in the standard QLBs.

Denotative versus Functional Languages

Suggestion: parameterized variables = functions

Should Schematron variables be improved to take parameters of some type (these being implemented by construction Xpath or XSLT functions? ) Perhaps all we need is that a Schematron variable can be bound to an XPath (or XSLT) function. This would allow any function that can be defined entirely with Xpaths. (XPath3 allows variables, comments, etc, so it is not so bad,)

Formal parameters are provided. This allows the let to act as a function declaration. (It might be that all the functions have a built in parameter to get the context as their first parameter, defaulted, That might allow some simplification. )

< sch:rule context="moneyList"     id="r1" >
    < sch:let name="sum-children"  value="$myContext/sum(*)"  as="function(*)" > 
       < sch:param name="myContext" / >
      < / sch:let >     

      < sch:assert test="r1:sum-children(.)  >  0" >
                A money list.s ubelement should be greater than 0 < / sch:assert >

N.B. The idea of assigning a function to a variable may be strange, but it is supported in e.g. LISP, C, Java, JavaScript etc. However, in XSLT it would implemented as an xsl:function with prefix added if needed. (I.e. it would probably not be implemented as an xsl:variable bound to an XPath3 inline function declaration.

That it is a function would be known by the sch:let/@as statement. The QLBs for XSLT1 and XSLT2 would be revised to allow sch:let/@as but only for "function(*)" because they don't need to (or cannot) support XSD typiing.

Misc

Should Schematron variables be improved to subsume XSLT3 accumulators and xslt:key? (Can such things be implemented in XSLT 1 and 2 with extra modes?)

You can see the direction here: do away with XSLT elements in Schematron.

P.S. Interesting to see that paper from 56 years ago various people discussing whether using indentation rather than delimiters is good for programming languages... P.P.S. Schematron's element is named "let" not "variable" as a reference to that paper, and so that it could be developed independently of xslt:variable. The other thing that I took from the paper (which we were taught in the Computer Languages course at Uni) is the idea that we want to think in terms of families of languages: so in Landin's terminology Schematron is the family and its XML syntax and Query Language Binding specifies the member.