The XSLT debugger can be used to debug an XSLT style sheet, or an XSLT application. When debugging, you can execute code one line at a time by stepping into, stepping over, or stepping out of the code. The commands to use the code-stepping functionality are the same for the XSLT debugger as for the other Visual Studio debuggers.
XSLT Style Sheets
You can start the debugger from the XML Editor. This allows you to debug as you are creating a style sheet.
To start debugging a style sheet
-
Open the style sheet in the XML Editor.
-
Enter the XML source document in the Input filed of the Properties window for the style sheet.
Note |
|---|
| To access this window, select Properties from the View menu, and then select Document from the drop-down list at the top of the Properties window. |
-
Select Debug XSL from the XML menu.
XSLT Applications
You can also step into XSLT while debugging an application. When you press F11 on an System.Xml.Xsl.XslCompiledTransform.Transform call, the debugger can step into the XSLT code.
Note |
|---|
| Stepping into XSLT from the XslTransform class is not supported. The XslCompiledTransform class is the only XSLT processor that supports stepping into XSLT while debugging. |
To start debugging an XSLT application
-
When instantiating the XslCompiledTransform object, set the enableDebug parameter to true in your code.
This tells the XSLT processor to create debug information when the code is compiled.
-
Right-click the Transform call, point to Breakpoint, and select Insert Breakpoint.
-
Press F5 to start the Visual Studio debugger.
-
Press F11 to step into the XSLT code.
The XSLT style sheet is loaded in a new document window and the XSLT debugger is started.
Example
The following is an example of a C# XSLT program. It shows how to enable XSLT debugging.
using System;
using System.IO;
using System.Xml;
using System.Xml.Xsl;
namespace ConsoleApplication
{
class Program
{
private const string sourceFile = @"c:\data\xsl_files\books.xml";
private const string stylesheet = @"c:\data\xsl_files\belowAvg.xsl";
private const string outputFile = @"c:\data\xsl_files\output.xml";
static void Main(string[] args)
{
// Enable XSLT debugging.
XslCompiledTransform xslt = new XslCompiledTransform(true);
// Compile the style sheet.
xslt.Load(stylesheet)
// Execute the XSLT transform.
FileStream outputStream = new FileStream(outputFile, FileMode.Append);
xslt.Transform(sourceFile, null, outputStream);
}
}
}
See Also