What gets checked
1. Well-formed XML
As you type, in your browser. An unclosed tag or a stray & is reported before anything is sent to the server, with the line it is on.
2. Compilation
The stylesheet is compiled by the processor for its version: XSLTC for XSLT 1.0, Saxon HE 12.9 for 2.0 and 3.0. Static errors such as XPST0003 come back with their line number.
3. A real run
It is then run against your input. Dynamic errors (type mismatches, missing documents, xsl:message terminate="yes") only show up here, and so does output that is valid but wrong.
An example
This XSLT 3.0 stylesheet is well-formed XML, so an XML validator would accept it. The XPath expression on line 3 is missing its closing bracket:
<xsl:stylesheet version="3.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<total><xsl:value-of select="sum(orders/order/@total"/></total>
</xsl:template>
</xsl:stylesheet>
Saxon rejects it at compile time, and this is the message you get, verbatim:
XPST0003: expected ")", found "<eof>" (line 3)
The error code is the W3C one, so it means the same thing in every Saxon-based tool, and the editor
turns (line 3) into a link that puts the cursor on the line. For the common codes there
is a page explaining the usual causes in the
XSLT error reference.
Validating against the right version
The version matters more than it looks. The same stylesheet can be valid in 2.0 and invalid in 1.0, because XSLT 1.0 has a much smaller function library. Validating with the wrong processor gives you a pass that means nothing in production.
| Version | Processor here | Use it when your stylesheet runs on |
|---|---|---|
| XSLT 1.0 | XSLTC (the JDK's built-in XSLT 1.0 compiler) | Java's default TransformerFactory, .NET XslCompiledTransform, libxslt, PHP, Python lxml, and stylesheets written for browsers |
| XSLT 2.0 | Saxon HE 12.9 | Saxon in 2.0 mode, older integration platforms |
| XSLT 3.0 | Saxon HE 12.9 | Saxon 9.8 and later, SaxonJS, modern integration platforms |
When an XSLT 1.0 stylesheet fails because it calls a 2.0 function, the editor names the function and
the version it needs, and offers to switch. Try upper-case(@country) in a 1.0 stylesheet
to see it.
How to validate your stylesheet
- Open the editor and paste your stylesheet into the left pane.
- Paste a sample of the XML it processes into the input parameter.
- Pick the version from the dropdown, or leave the one in your
xsl:stylesheetelement. - It runs as you type. Fix the first error, and the next one shows up.
If the stylesheet compiles and the output is still not what you expected, switch on trace (XSLT 2.0 and 3.0) to see which templates fired and in what order.
Also available
Need to see what a stylesheet renders rather than whether it compiles? Use the XSLT viewer →
Debugging the XPath inside it? Try the XPath tester → · Version-specific pages: XSLT 2.0, XSLT 3.0.
Frequently Asked Questions
- How do I validate an XSLT stylesheet online?
- Paste it into the left pane of XSLT Playground, add a sample XML document as the input, and pick the XSLT version. The stylesheet is checked for well-formedness as you type, then compiled and run by a real XSLT processor. Any error appears below the editor with its line number; click it to jump there.
- Does an XSLT validator check against a schema?
- XSLT has no single schema that catches real mistakes. A stylesheet can be valid against the XSLT schema and still fail to compile because of a bad XPath expression, an undeclared variable or a function the version does not have. That is why this validator compiles the stylesheet with the processor that will run it, instead of checking it against a schema.
- Why does my stylesheet work in XSLT 2.0 but not in 1.0?
- Functions such as upper-case(), tokenize(), replace(), format-date() and current-group() do not exist in XSLT 1.0. When the error comes from one of them, the editor says which version the function needs and offers to switch the stylesheet to it.
- Is the stylesheet validated against my real data?
- Yes, if you paste it. Some errors only appear at run time with particular input, such as a type error on an empty attribute or a division by zero, so validating with a representative sample catches more than compiling alone.
- Is the XSLT validator free?
- Yes. No account, no installation and no limit on stylesheets. Transformations run on our server with a timeout of a few seconds each.