Sunday, August 03, 2008

Debugging XSLT using Visual Studio 2005 / 2008

Visual Studio has the ability to debug XSL stylesheets. This a extremely useful feature that a few seem to know exist and use regularly.

Most of the projects I'm involved with use XSLT in one way or another. And the VS debugger along with other tools have saved me countless hours of frustration.

Here's a quick guide to get you started:

  1. Create / Open up the XSL file using Visual Studio
  2. Setup break points as necessary
    breakpoints
  3. Make sure that the XML Editor toolbar is visible
    XML Toolbar
  4. Click on the Debug XSLT button to start debugging
    debug_xsl
  5. A warning message would appear asking you to setup an input file. This would be the XML file that needs to be transformed. Click YES and select the input file.
    filename
  6. Step through the code.
    stepthrough

The only disadvantage or limitation rather is that you can't specify values for xsl:param variables. The workaround I use is to re-define the parameter as an xsl:variable , set the expected input value.

xsl_variable

On a related note, XslCompiledTransform class supports stepping into the stylesheet while debugging. The only pre-requisite is that the class should be instantiated with the debug parameter value set to true . Detailed instructions provided here.

1 comment:

Todd said...

That button is disabled for me

How can i get it enabled?

I followed your steps exaclty.

I can see the button,
it's just disabled.