Debugging XSLT Style Sheets in Visual Studio Options

codeling Posts: 1100 Points: 4620
Posted: Wednesday, June 15, 2016 12:02:35 PM

You can 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.

To start debugging an XSLT application

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

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

    Alternatively, you can add a break point to the style sheet and run your application.

codeling Posts: 1100 Points: 4620
Posted: Wednesday, June 15, 2016 12:03:53 PM

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.

      // Execute the XSLT transform.
      FileStream outputStream = new FileStream(outputFile, FileMode.Append);
      xslt.Transform(sourceFile, null, outputStream);

codeling Posts: 1100 Points: 4620
Posted: Wednesday, June 15, 2016 12:08:50 PM

Exception “stylesheet is too complex” when loading large XSLT

An exception "The stylesheet is too complex" when attempting to load an XSLT stylesheet in .NET 4.0.


Adding the following setting to your config file and the problem should go away.

<?xml version="1.0" encoding="utf-8" ?>
    <sectionGroup name="system.xml">
      <section name="xslt" type="System.Xml.XmlConfiguration.XsltConfigSection, System.Xml, Version=, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false"/>
    <xslt limitXPathComplexity="false"/>



Users browsing this topic