System properties: early evaluation
The argument to the XSLT system-property() function is generally written as a string literal, and Saxon will generally evaluate the function during stylesheet compilation, which allows optimization based on the result (for example, code within the test "if (system-property('xsl:vendor') eq 'Microsoft')..." will be eliminated at compile time).
This strategy is wrong in cases where the stylesheet is exported, and is then executed in a different environment. A stylesheet that is being exported is necessarily compiled under Saxon-EE, where system properties such as xsl:is-schema-aware and xsl:supports-higher-order-functions will take the value "yes"; but the exported stylesheet may be evaluated in an environment where schema-awareness and higher-order-functions are not supported. Evaluation in these cases should therefore be deferred until run-time.
Note that there's nothing much we can do about calls that appear within static expressions, e.g. use-when. These are necessarily evaluated at compile time.
#3 Updated by Michael Kay over 4 years ago
On the saxon-dev branch I have made some changes so system-property avoids early evaluation of certain properties, like is-schema-aware. But I'm not sure this is the final solution. I think that when we're compiling a stylesheet for export, we need to be told something about the target execution environment. For example, we want static errors if there are calls on fn:sort() and the target environment is one that doesn't support higher-order functions; similarly, use of system-property() and function-available() within static expressions should give a result that reflects the capabilities of the target environment.
#4 Updated by Michael Kay over 4 years ago
#5 Updated by Michael Kay over 4 years ago
I have implemented this as follows:
(a) an option -target is available on the Transform command line. The value is the target edition for executing the stylesheet, e.g. EE, PE, HE, JS.
(b) the same option is available in s9api as XsltCompiler.setTargetEdition(), or if required as an option on the CompilerInfo.
(c) the option affects the results of system-property(), element-available(), and function-available() when executed at compile time (either in ordinary code, or in a use-when expression). For example, if the target edition is HE, then element-available('xsl:merge') returns false.
There is scope for further use of this option in future, either (a) for early diagnostics if the stylesheet uses constructs that are not available on the target platform, or (b) for generating code in a different way, e.g. fallback code for streaming.
#6 Updated by Michael Kay over 4 years ago
- Status changed from New to Resolved
- Applies to branch 9.8 added
- Fix Committed on Branch 9.7, 9.8 added
Changes committed to the 9.7 and 9.8 branches as described above. Note, the changes on the 9.8 branch are not fully operational because other code needed for target:JS is not yet present on this branch.
Please register to edit this issue