Debugging XSLT from a Content Query WebPart

Hi,

Today I receive several questions about debugging CQWP XSLT. Although I love writing them in Notepad and doing the final transformation in IE ;), it would be great to use the features of Visual Studio 2005 (I will do other post for Visual Studio 2008) in order to debug our files in MOSS, without MOSS.

As you can read in the referenced links, there are, OOB, 3 XSL files for the CQWP in MOSS. So in order to start you should take a copy of those files, and take a sample xml for your query.

The sample query can be taken from the CQWP itself, configuring the query in a test page, and adding the following element in the first template of the ContentQueryMain (lines 2-4):

  1. <

xsl:template match="/">

<

textarearows="10"cols="30" >

<

xsl:copy-ofselect="." />

</

textarea >

<

xsl:call-template name="OuterTemplate" />

</

xsl:template>

CQWP Configuration

CQWP Sample XML

That will allow you to copy&paste the sample xml for your query. You shoud add the correct encoding for your data. Mine is: <?xml version="1.0" encoding="iso-8859-1"?> as the first line in the sample xml.

Then you can just open Visual Studio (you will have intellisense for XSL schema, Validation, etc..), Open the XSL files, and in the Input property of the XSL file select the sample XML. Then in the XML Toolbar, you will need to click Debug XSLT (5th button), and you are on the right way!.

Visual Studio 2005 XML Toolbar

In order to debug the XSLT's we will use, we will need to include the import element on the top of the Main XSL file, linking the item XSLT (line 8):

  1. <

xsl:stylesheet

version="1.0"

exclude-result-prefixes="x xsl cmswrt cbq"

xmlns:x="https://www.w3.org/2001/XMLSchema"

xmlns:xsl="https://www.w3.org/1999/XSL/Transform"

xmlns:cmswrt="https://schemas.microsoft.com/WebPart/v3/Publishing/runtime"

xmlns:cbq="urn:schemas-microsoft-com:ContentByQueryWebPart">

<

xsl:importhref="ItemStyle.xsl"/>

But I couldn't get rid of the custom functions in the namespace cmswrt, so you will need to change those (as cmswrt:EnsureIsAllowedProtocol); and you will get the result in the result window:

Visual Studio debugging XSL

Cheers!

References

https://msdn2.microsoft.com/en-us/library/ms255605(VS.80).aspx

https://blogs.msdn.com/ecm/archive/2006/10/25/configuring-and-customizing-the-content-query-web-part.aspx

https://msdn2.microsoft.com/en-us/library/aa981241.aspx