XSLT Quality checks your XSLT to see if it adheres to good or best practices.
xslt-quality.sch: the master Schematron file. This is the one (and only) Schematron file you need to point to. It has a number of submodules for groups of tests:
- xslt-quality.sch: Mukul Gandhi XSL QUALITY rules
- xslt-quality_common.sch: a few common tests without specific category
- xslt-quality_documentation.sch: tests on documentation
- xslt-quality_namespaces.sch: tests regarding namespaces
- xslt-quality_typing.sch: tests on variable / parameter types
- xslt-quality_writing.sch: tests on writing
- xslt-quality_xslt-3.0.sch: tests on specific XSLT 3.0 features
The modules listed above are subject to change in number, name, and contents, but the master Schematron file will not (from XSLT Quality 1.0.0)
The Schematron suite depends upon an XSLT library whose master file is here: xslt-quality.xslt.
A subset of this code is a revision of code written by Mukul Gandhi in his XSL QUALITY project. Special thanks to him for allowing me to implement his rules under Apache License Version 2.0.
All other code is released under Apache License Version 2.0
XSLT Quality uses schematron sch:include to load each sub-module. Unlike xsl:include that allow to load a full XSLT, sch:include works like replacing the call by the content of the module.
For this reason, submodule only contain sch:pattern, and every other sch elements (sch:ns, sch:let, sch:diagnostic, etc.) has to be declared in the main schematron xslt-quality.sch
Some submodules might not be valid (missing variable, dignostic, etc.), but opening the Oxygen project (xslt-quality.xpr) will show them valid as xslt-quality.sch has been added as "Master file" in the project.
XSLT Quality is using Schematron applied on any XSLT and generates errors, warning and info. At this end we use the @role attribute.
The main schematron imports xslt-quality.xslt with xsl:include which is not a schematron element.
The Schematron engine you are using must support this extension, typically by setting allow-foreign parameter to true.
First make sure "Allow foreign elements (allow-foreign)" is activated here:
- Go to Options > Preferences > XML > XML Parser > Schematron
- Check the box "Allow foreign elements (allow-foreign)" if it's not
- Click OK
You can use XSLT Quality in Oxygen by creating a validation scenario that you apply to the XSLT you want to valid.
It's also possible to get any XSLT in Oxygen to be validated with XSLT quality without applying any specific scenario. Do the following:
- Go to Options > Preferences > Document type association
- Select "XSLT" and click Edit
- Go to "Validation" tab
- Double click on the single scenario "XSLT"
- Click Add
- In the new entry click "XML Document" under File type.
- Double-click on the Schema column.
- Click Use custom schema, and use the URL bar to point to
xslt-quality.sch - Click OK (Three times)
In this way, both Oxygen schematron and xslt-quality schematron will be applied to your XSLT.
Later, I intend to make XSLT-quality available on Maven Central, then you should be able to load xslt-quality.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:
-
#7 xsl-qual : have a look at comments on http://markmail.org/message/y5cunpvfpy54wqe6
-
#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>
-
#12 Using
<xsl:value-of>where<xsl:sequence>is enough -
#13 Writing:
That means 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)