Is there a tool to check if an XSLT stylesheet follows coding standards?
How can we check whethe开发者_StackOverflow中文版r an XSLT stylesheet is following all the coding standards? Is there a tool where we can specify our own rules and find out if the stylesheet conforms?
First of all, there is nothing like
"all coding standards"
...
This said, take a look at the XSLT Lint, developed by Mukul Ghandi, and published Dec. 2008:
http://lists.xml.org/archives/xml-dev/200812/msg00178.html
There is also one published recently by Andriy Gerasika:
http://www.biglist.com/lists/lists.mulberrytech.com/xsl-list/archives/201102/msg00103.html
In case you are interested in functional programming with XSLT, take a look at FXSL.
Finally, if by "all coding standards" you mean "style", you may look at my answers in the xslt tag of SO, to learn a little bit more about "push style" and programming without explicit logical instructions.
Well, if the stylesheet works, it should be valid, right?
Other than that, i think all the big XML IDEs like Altova's XMLSpy provide some sort of schema validation, if that's what you're looking for.
XSL stylesheets is a XML language. So, validation tools available for XML still applies here. So, DTD or XML namespaces can be used to define the rules to check. Link to the location where the DTD/ns reside in the XSL sheet. Then tools like Xerces can be used for validating the document.
If you are using ANT, xmlvalidate
task will do this automatically by invoking Xerces SAXParser.
<target name="validate" if="perform-validation-dtd">
<xmlvalidate file="${input-xml}"
classname="org.apache.xerces.parsers.SAXParser"/>
</target>
xmllint program validates an XML file against its DTD (Document Type Definition) and reports on any differences. Read more here
Well, an XSLT stylesheet is XML itself of course; you could easily write an XSLT that looks for patterns.
For example:
<xsl:template match="xsl:for-each">
<xsl:text>Inappropriate use of xsl:for-each; should be using templates instead</xsl:text>
</xsl:template>
if your policy includes not using xsl:for-each
.
Or, you could write a schema that expands on the xslt one.
精彩评论