This repo is about testing your XSLT quality. It contains a main schematron to be applied to your XSLT:
checkXSLTstyle.sch: it doesn't contain any rules, it's only a wrapper to extend rules of each modules:
xsl-quality.sch: an iso-schematron implementation of Mukul Gandhi XSL QUALITY xslt. Special thanks to him for allowing me implementing his rules under Apache License Version 2.0.
xsl-common.sch: common schematron rules for good XSLT practice
You may use the main schematron wrapper or only the module you wish.
Using XSLT schematron with Oxygen 19+
From version 19, Oxygen has a default schematron which is automaticaly applied to any edited XSLT, aiming at checking code quality:
[INSTALL.DIR]/Oxygen XML Developer [version]/frameworks/xslt/sch/xsltCustomRules.sch
xsltDocCheck.sch for Oxygen 19.1+)
To apply xslt-quality schematron you have to customize Oxygen's schematron like this:
Be sure you have the rights privileges to write this file
Change the query binding to xslt3 :
Because the xslt-quality schematron is using xslt 3.0 functions, it is necessary to harmonize every schematron.
Add this line after the namespaces declarations (sch:ns):
- one cannot use
<sch:include>as explained here;
- You also could load only one (or more) module(s) independently like
Finally make sure "Allow foreign elements (allow-foreign)" is activated here:
Options > Preferences > XML > XML Parser > Schematron
Because xslt-quality schematron embeds xslt function to make xpath rules easier to write.
In this way, both Oxygen schematron (
xsltDocCheck.sch) and xslt-quality schematron (
checkXSLTstyle.sch) will be applied to your XSLT.
Later, I intend to make this repo available on Maven Central, then you should be able to load
checkXSLTstyle.sch (or any module) from a jar distribution with a catalog.xml, using "artefactId:/" as protocol and/or using the
cp protocol by cmarchand
#4 Move rule "use-resolve-uri-in-loading-function" elsewhere cause it's too specific?
#6 Check for conventions:
#8 Named template for generating XML elements VS functions to return atomic values as a good practice?
#9 Should the template ordering be watched by the schematron (copy template at the end, templates with @mode together, etc.)
#10 Unused templates, functions, global variables/parameters might not be an error (when the xsl is a library)
#11 Check that XSLT default templates are not used like:
<xsl:template match="/"> <xsl:apply-template> </xsl:template>
That mean parsing the xsl as text here, something like:
<sch:let name="xslt.txt" select="unparse-text(base-uri(/))"/>
- indent with spaces
- No break line inside templates
- Space around operators ( =, +, > etc)