Skip to content

FredericLanic/xslt-quality

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

53 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

XSLT Quality

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:

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.

License

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

Technical notes

Modularization

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.

role attribute

XSLT Quality is using Schematron applied on any XSLT and generates errors, warning and info. At this end we use the @role attribute.

XSLT library : allow foreign

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.

Using XSLT Quality with Oxygen

First make sure "Allow foreign elements (allow-foreign)" is activated here:

  1. Go to Options > Preferences > XML > XML Parser > Schematron
  2. Check the box "Allow foreign elements (allow-foreign)" if it's not
  3. Click OK

Validating a single XSLT

You can use XSLT Quality in Oxygen by creating a validation scenario that you apply to the XSLT you want to valid.

Automatic validation of each XSLT

It's also possible to get any XSLT in Oxygen to be validated with XSLT quality without applying any specific scenario. Do the following:

  1. Go to Options > Preferences > Document type association
  2. Select "XSLT" and click Edit
  3. Go to "Validation" tab
  4. Double click on the single scenario "XSLT"
  5. Click Add
  6. In the new entry click "XML Document" under File type.
  7. Double-click on the Schema column.
  8. Click Use custom schema, and use the URL bar to point to xslt-quality.sch
  9. Click OK (Three times)

In this way, both Oxygen schematron and xslt-quality schematron will be applied to your XSLT.

MAVEN

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

TODO

  • #4 Move rule "use-resolve-uri-in-loading-function" elsewhere cause it's too specific?

  • #5 Use quickFix / diagnostic?

  • #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)

About

XSLT Quality

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • XSLT 100.0%