tags:

views:

943

answers:

8

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.

+2  A: 

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.

Javier
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.
Sam Hoice
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
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
+6  A: 

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!

Pramod
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.
Sam Hoice
Just download the Express edition of Visual Studio then. It's free.
Code Trawler
A: 

As I've been searching for an answer, I've come across a tool called Xalan. Has anyone had any experience with it? It appears at first blush to do what I want.

Sam Hoice
Yes, Xalan is an XSLT processor that also does syntax checking while processing the Stylesheet. But be aware that it only supports XSLT 1.0 syntax. If you want a processor for XSLT 2.0 stylesheets, use Saxon ( http://saxon.sourceforge.net/ )
chiborg
+3  A: 

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.

James Sulak
A: 

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.)

Robert Rossney
+2  A: 

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.

David Robbins
+1  A: 

I use Cooktop which is pretty good, nice and simple :

http://www.xmlcooktop.com/

+1  A: 

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.

chiborg