web analytics

Debugging XSLT Style Sheets in Visual Studio

Options

codeling 1602 - 6666
@2016-06-15 12:02:35

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.

@2016-06-15 12:03:53

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);
    }
  }
}
@2016-06-15 12:08:50

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.

Solution

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

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

 

 

Comments

You must Sign In to comment on this topic.


© 2024 Digcode.com