<Debug /> your XSLT

Composite 3.8 come with a new feature that allows XSLT developers to use professional XSLT editors and debuggers.

Programs like Visual Studio and Eclipse+oXygen give you the power of breakpoints and single step debugging in your XSLT, but other tools exists and in this guide we will use a simple, but free and downloadable, program called Cooktop. As far as free programs go Cooktop is a good XSLT editor (see http://www.xmlcooktop.com/ for more info).

Create a new XSLT Identifier using a professional XSLT editor

The following steps illustrate how you would create a new XSLT Identifier that prints XHTML based on XML from several Data Query Definitions, primarily using Cooktop as an editor. In the following it is assumed that you are familiar with XSLT and that the Data Query Definitions required for your XSLT task already exists.

  1. On the Templates fan, right click the Template Group “Normal templates” and select “Manage Plug-ins”.
  2. In the lower “Add plug-in instance” section, select the plug-in “Data Query XSL Render” and click the button “Add plug-in instance”.
  3. Rename the identifier to “$$MyTooledXslt;” and click the button “Add plug-in to Template Group”
  4. On the Datamap fan, open “Data Query XSL Definitions”, “Data Query XSL Render”. Locate the node named “$$MyTooledXsl;” in the alphabetically ordered list. Double click it (edit it).
  5. On the general fan for $$MyTooledXsl; select the data queries you want XML from (for example purposes, please select more than one).
  6. Edit the XSLT code and delete all <xsl:template /> elements (with content)
  7. Insert this block instead:

    <xsl:template match="/">
       <Debug />
    </xsl:template>

  8. Save the XSLT definition (Ctrl+S).
  9. On the Pages fan, edit a page suitable for debugging or create a new page.
  10. Write “$$MyTooledXsl;” in the content area and save.
  11. On the preview of the page you should see a button labeled “$$MyTooledXsl; XML”. Click it.
  12. A pop-up window containing XML appears. The XML you see now is the XML your XSLT saw when it rendered the <Debug /> tag. The XML is emitted inside the HTML block that the <Debug /> created, and the XML does not change, unless you refresh the page. An XML refresh will require a page refresh.
  13. Click the “Raw view” button, select all the XML and simply, but effectively, copy it to your clipboard.
  14. Start the Windows application Cooktop (Cooktop is used here as an example – feel free to use other tools).
  15. Select File | New, choose “Xml Cooktop” and press the OK button.
  16. Select the “source(xml)” tab and paste the XML from the debug window. Press F8 to format the XML.
  17. Select the “stylesheet(xsl)” tab and select the menu option Code Bits | XSL Template.
  18. Start writing your XSLT (this example does not show you how XSLT works).
  19. Press F5 to execute your XSLT and see the result. The first time you are required to save the two source files. Save them. File names are not important in this example.
  20. Use the “xpath console” tab to test XPath expressions and see what scope they yield. Prefix your XPath with n: and press the Enter key to execute the XPath query, like

    n:/xml/Query

  21. Finish writing your XSLT and copy the finished XSLT to your clipboard.
  22. Go to the Composite administrative module, edit the Data Query XSL Definition $$MyTooledXsl; and paste the XSLT on top of the old code.
  23. Save.
  24. Preview the page containing the identifier. You should see the XSLT code you created in Cooktop in action on your live XML feed.

The above example shows you how you could go about creating a new XSL Render Identifier using Cooktop as your editor. You can of course copy both the debug XML and the Composite XSLT from your Identifier into Cooktop if editing existing XSLT code is your task.

Locating problems in your XSLT

If your XSLT code acts unexpected in some circumstances, for instance if a particular product is being rendered, you can use the <Debug /> feature to easily capture the XML that provokes the problem.

First ensure that the <Debug /> element is emitted by your XSLT. The <Debug /> element will not influence the behavior of public pages, so you can safely use it in production environments.

Use the page preview mode to browse to a page containing the Identifier and execute the task required to provoke the error, like using a search form or selecting a product link. When the error occurs, press the Identifier XML button and examine the XML.

If the problem isn’t apparent from the XML view, copy the raw XML into your professional XSLT editor along with the XSLT code for the identifier and start working on it and debugging it (if your tool permits).

When the problem is fixed, copy the revised XSLT back on top of the old XSLT.

My modules


© 2009 Composite A/S, Danmark
Tlf: +45 39 15 76 00 | info@composite.net
Composite A/S er Microsoft Certified Partner
Composite CMS overholder standarden for valid CSS
Composite CMS overholder standarden for valid XHTML 1.0
Printet fra http://www.composite.net/composite-1694.htm
Findes på denne sti: Composite Developer | 3.x technologies | XSLT | Guides and tutorials | How to <Debug /> your XSLT