I have a Java servlet which generates xml, translates it with an xslt stylesheet, and then displays the resulting HTML. This is the first time I've worked with xslt. What's a good way to debug xslt? I have (or can get) some sample XML files to apply the transform too. But I'm not really even sure of the syntax so something that would give me syntax warnings would be great.
-
There is a detailed comment on anothur similar question https://stackoverflow.com/a/9726173/1513775 – d.j.yotta Nov 08 '22 at 03:58
9 Answers
If you want to do "printf-style" debugging and don't want to litter your output with debugging data, use the <xsl:message>
tag to generate debugging output while processing the stylesheet. With the terminate="yes"
attribute you can even halt the processing of the stylesheet.

- 26,978
- 14
- 97
- 115
-
5A) Using commandline `xmllint mytransform.xsl` as a basic syntax checker is helpful to catch mismatched braces etc. B) Also running a commandline processor in verbose mode can be really helpful esp. when you don't know why xslt is choking on your code. `xsltproc -v mytransform.xsl input.xml &>log.txt` dumps a LOT of info from the xsltprocessor. Filter out the noise by using search with vim or grep for your debug messages like "DEBUG: Start of my code" or useful string patterns like 'applying template'. – GuruM Nov 08 '12 at 11:08
Xalan should give you useful errors when you try to use an invalid XSLT. If you want something more powerful, one option for debugging XSLT is Oxygen XML Editor. It is integrated with Xalan and Saxon transform engines. Its debugging mode allows you to set breakpoints, watch variables, and provides other such basic debugging functionality. It may be overkill for you want, but it's very good.

- 31,389
- 11
- 53
- 57
I once had to write and debug some complex XSLT documents. At the time I used debugged "printf-style" by outputting a lot of intermediate values. I later found out that there is a much easier way to do this - Altova XMLSpy. It allows you to single-step through the style-application process, watch intermediate output, etc. etc.
VS8 also has XSLT debugging support. See here: http://msdn.microsoft.com/en-us/library/ms255605(VS.80).aspx
I should also mention that both XMLSpy and VS8 have syntax highlighting as well. If you specify a XSD in your XML, VS8 even gives you intellisense!

- 37,270
- 24
- 156
- 208

- 9,256
- 4
- 26
- 27
-
Unfortunately, I can't justify the cost to my boss for the limited use I'd get, for now. If this turns into a longer term project, I may be able to get one or the other. – Jonathan Adelson Oct 20 '08 at 14:27
-
Just download the Express edition of Visual Studio then. It's free. – Code Trawler Oct 20 '08 at 15:26
-
A great post about Visual Studio's XSLT debug support here: http://www.codeproject.com/Articles/41992/Debugging-XML-Transforms-XSLT-with-Visual-Studio – Merenzo Jan 26 '12 at 05:00
-
On a separate issie, I'm having a performance related issue. I need to use the printf style logging to simply insert timestamps before and after critical sections of code to find which XSLT sections are consuming too much time. Any links to C# window's log write from XSLT? – bsd Jun 04 '12 at 15:46
PHPStorm and the other IntelliJ IDEs (commercial) support debugging XSLT. You can step through the document and see the output being generated step by step.

- 22,122
- 12
- 111
- 127
I work with XSLT nearly every day, and have for six or seven years.
I've found that "printf-style" debugging of XSLT is so effective that I've never derived a benefit from using any other debugging mechanism (and I've tried XMLSpy and Visual Studio). It does sometimes happen that I want to be able to inspect the value of a variable and building logic that outputs it is a hassle. But that's pretty rare.
It may be that having a debugger would have made learning XSLT easier. (Anything would have.)

- 94,622
- 24
- 146
- 218
when learning, a syntax highlighting editor is usually enough for me (of course with the ref doc open on another window.
Kate is a great editor for XML and XSLT.

- 60,510
- 8
- 78
- 126
-
A syntax highlighter is helpful. I'm using VI on my server right now because I'm not done setting up my dev environment. But what I really want is to be able to run the xml and xslt through a processor and get error messages or whatever without having to run the whole servlet process. – Jonathan Adelson Oct 20 '08 at 14:07
-
try a command-line xslt processor; i use xalan, but anyone would do. I'm sure vi can run it and won't be surpriesed if it could even parse the error outputs like it does with compilers – Javier Oct 20 '08 at 14:31
-
Oh, you absolutely want to be executing your transforms and viewing their output in your IDE. I don't think a debugger's very important, but that's essential. – Robert Rossney Oct 21 '08 at 01:02
Xselerator is s great XSL debugging tool that will:
- Let you step through your XSLT dom
- Create watch statements
- Evaluate XPath statements against you XML DOM
- IDE with Intellisense
I've used this for years and it is a great tool.

- 9,996
- 7
- 51
- 82
An answer specifically for debugging XSLT 3.0 with <xsl:message>
:
XSLT 3.0 has a new serialize()
function that can help when used inside an xsl:message
instruction.
However, for the new array
and map
types you need to use the adaptive serialisation method instead of default XML serialization:
<xsl:message select="serialize($n, map{'method':'adaptive'})"/>
The current drawback with serialize
though is that it does not format the output.
A small xpath-result-serializer XSLT project provides ext:print()
and ext:println()
functions as an alternative to serialize()
. There format (and optionally colorise) the XSLT output.
The output text uses an abbreviated notation for maps/array optimised for the human reader rather than a parser. For XML nodes with context, the XPath location is output alongside any text or attribute values.

- 2,087
- 1
- 22
- 27
Microsoft Visual Studio is also a great tool for xslt debugger. But you must install the

- 11
- 7
-
-
1You can edit the answer. Though I don't see that this adds anything to this ten-year-old question, that hasn't been mentioned yet. – Mr. T Feb 23 '18 at 14:04