Sunday, December 28, 2008

A static code quality tool, for XSLT code

I wrote a little tool to measure and enhance the code quality, of XSLT programs/scripts. It's available at,

I hope that the XSLT community might find this useful.

Any comments/suggestions about this tool would be most welcome.


vito piserchia said...

I' ma using your tool for static validation of xslt files.
Above all, thanks for sharing.

Second,i found this rule:
<rule name="NameStartsWithNumeric">
The variable/function/template name starts with a numeric character
//(xsl:variable | xsl:template)[(string-length(@name) > 1) and matches(@name, '[0-9].+')] | //xsl:function[(string-length(substring-after(@name, ':')) > 1) and matches(substring-after(@name, ':'), '[0-9].+')]

As variable/@name (function|template)/@name template/@match MUST BE QName or NCName, you could change the preceding xpath to:

<xpath>//(variable|template|function)/matches(@name,'^(\i|\i-[:])')< | //template/matches(@matches,'^(\i|\i-[:])')</xpath>

Where \i specifies the first allowed character.

vito piserchia said...

Fix for the last xpath:

//(xsl:variable|xsl:template|xsl:function)[not(matches(@name,'^(\i|\i-[:])'))] |


I suggest also to change the priority from 5 to 1, because these types of violation produce a runtime error.

Hope this helps


PS: The same xpath could be applied every where the xsl schema refers to an NCName or QName type

Mukul Gandhi said...

Thanks for your comments.

My intention for this rule was to avoid variable, template and function names to begin with a numeric character. i.e., names like 1abc should be avoided (it's considered a bad practice in programming).

Different users may have different needs in their projects.

You are free to change the XPath expression of this rule, or of any other rules. You could add any new rules, or even remove any rules provided by me, if you don't need it. You are also free to change priorities provided by me for any of the rules.