Debugging XSLT from a Content Query WebPart

Debugging XSLT from a Content Query WebPart

  • Comments 1

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="/">
  2. <textarea rows="10" cols="30">
  3. <xsl:copy-of select="."/>
  4. </textarea>
  5. <xsl:call-template name="OuterTemplate" />
  6. </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
  2. version="1.0"
  3. exclude-result-prefixes="x xsl cmswrt cbq"
  4. xmlns:x="http://www.w3.org/2001/XMLSchema"
  5. xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  6. xmlns:cmswrt="http://schemas.microsoft.com/WebPart/v3/Publishing/runtime"
  7. xmlns:cbq="urn:schemas-microsoft-com:ContentByQueryWebPart">
  8. <xsl:import href="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

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

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

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

Leave a Comment
  • Please add 3 and 6 and type the answer here:
  • Post