Debugging Stylesheets - Getting Started

The Stylus Studio debugger allows you to follow XSLT processing and detect errors in your stylesheets. Stylus Studio includes sample files that you can experiment with to learn how to use the debugger. To get you started, this section provides step-by-step instructions for using the debugger with these sample files. You should perform the steps in each topic in the order of the topics.

For complete information about how to use the debugger, see Chapter 6Debugging Stylesheets.

In addition, Stylus Studio allows you to observe and debug the interaction between your Java code and XML data. See Debugging Java Files.

This section includes the following topics:

Before you begin

To get started, you'll need to start Stylus Studio if you haven't already. See Starting Stylus Studio.

Setting Up Stylus Studio to Debug Sample Files

To set up Stylus Studio to debug sample files:
1. In the Stylus Studio tool bar, select File > Open.
2. In the Open dialog box that Stylus Studio displays, navigate to the examples\VideoCenter directory in your Stylus Studio installation directory and open the videosDebug.xsl stylesheet.

Alternative: If the Stylus Studio Project window is open, you can access this stylesheet from the examples project.

Stylus Studio displays the videosDebug.xsl stylesheet in the XSLT editor.

3. In the XSLT editor tool bar, click Preview Result to run the predefined scenario DebugVideosScenario. The source XML document is videos.xml.

Stylus Studio applies the stylesheet and displays the results (a finished HTML page that displays information about a single video) in the Preview window.

Figure 53. Preview of videosDebug.xsl

Inserting a Breakpoint in the Sample Stylesheet

This topic is part of a sequence that starts with Setting Up Stylus Studio to Debug Sample Files.

As with any debugger, in the Stylus Studio XSLT debugger you insert a breakpoint where you want to suspend processing and examine what is going on. You can do this using the Debug menu or the debug set of tools in the tool bar.

Tip

 

Tools in the tool bar are in grouped by function. These groups, like the one for debug tools shown here, are dockable and can be moved anywhere you please.

To insert a breakpoint in the sample stylesheet:
1. In the XSLT Editor, click in line 202. Line numbers appear in the lower right corner of the XSLT Editor window. Line 202 starts with
<xsl:template match="director">
       

    

Tip

 

To display lines in Stylus Studio text editors, click Tool > Option > Editor General, and select Show line numbers.

2. In the Stylus Studio tool bar, click Toggle Breakpoint .

Alternative: If you prefer, select Debug > Toggle Breakpoint, or press F9.

Stylus Studio displays a red circle to the left of the line that contains the xsl:template match="director" instruction. The XSLT processor will stop processing when it gets to the instantiation of this template.

Figure 54. A Red Circle Shows Where Breakpoints Are Set

Do not do it, but to remove a breakpoint, you click in the line that has the breakpoint and then click Toggle Breakpoint (or F9). The Toggle Breakpoint button and F9 key operate as toggles.

3. Press F5 to start debugging.

Alternative: In the Stylus Studio tool bar, click Start Debugging .

The XSLT processor displays a yellow triangle to indicate where processing has been suspended. Instead of the finished HTML created when you first ran the scenario, the Preview window displays just the HTML code because complete processing of the XSLT was suspended before the finished HTML could be rendered.

Figure 55. Yellow Triangle Shows Where XSLT Processing Stopped

Do not do it, but to stop debugging, you can click Cancel in the lower right corner of the XSLT editor window, or click Stop Debugging in the Stylus Studio tool bar.

If you click Preview Result instead of pressing F5, Stylus Studio applies the stylesheet without running the debugger. Pressing F5 always invokes the debugger. If there are no breakpoints, and no errors, processing completes and Stylus Studio displays the result in the Preview window.

Gathering Debug Information About the Sample Files

This topic is part of a sequence that starts with Setting Up Stylus Studio to Debug Sample Files.

When XSLT processing is suspended at a breakpoint, Stylus Studio displays the Variables, Call Stack, and Watch windows.

Figure 56. Variable, Call Stack, and Watch Windows Appear During Debugging

You can use the information in these windows to learn about potential and actual problems encountered in your XSLT processing.

Tip

 

You can also control the display of these windows using the Debug menu, shown here, or the tool bar.

The Variables Window

The Variables window displays a list of variables and their values when processing was suspended.

Figure 57. Variables Window

As you can see, the stylesheet defines the VideoName parameter, which had no value when processing was suspended. In addition, the Variables window shows you that when processing was suspended, the processor was operating on the first director child element of the first video child element of the first videos child element of the first result element.

The Call Stack Window

The Call Stack window displays a history of the steps the processor performed to reach the point at which processing was suspended, including the names of the templates that are currently instantiated, in most recent-to-oldest order.

Figure 58. Call Stack Window

In this example, the XSLT processor has instantiated the director template, which is part of the instantiation of the video template, which is part of the instantiation of the template that matches the root node.

To step out of debug, click Step out , or press Shift+F11.

The processor completes the instantiation of the director template, which adds some HTML to the Preview window. The yellow triangle moves to show the new location in the XSLT source.

Figure 59. Stepping Out Advances the Processor

As you can see in the Call Stack window, the processor is now two levels deep in the template that matches the root node, instead of three levels deep as it was previously. The value of the context node in the Variables window is /result[1]/videos[1]/video[9] (it was /result[1]/videos[1]/video[9]/director[1]).

The Watch Window

If your application contains a lot of variables, the Watch window allows you to focus on the variables in which you are particularly interested.

Figure 60. Watch Window Lets You Track Variables

To enter a variable to watch:
1. Double-click the Name field.
2. Type the name of the variable you want to watch and press Enter.

As processing continues, the Watch window displays the values of the variables you specify.

Ending Processing During a Debug Session

To end processing during a debug session:
1. In the Preview window, click any line of text.

In the XSLT Source tab, Stylus Studio displays the blue backmapping triangle that indicates the line in the stylesheet that generated the output line you clicked.

2. In the lower right corner of the XSLT editor, click the Cancel button to end processing.

Figure 61. Cancelling Processing During Debugging

Stylus Studio displays a notification message that indicates that processing has been stopped and, optionally, allows you to jump to the location where processing ended.

Figure 62. You Can Jump to Where XSLT Processing Ended

3. Click Yes to jump to the location where processing ended.

The cursor appears on line 146 of the XSLT Source tab, which contains

<xsl:apply-templates select="director"/>.
       

    
4. In the XSLT editor tool bar, click Open XML from Scenario .

Stylus Studio displays the XML source document that the stylesheet operates on. As you can see, the first result element is the document element.

Figure 63. Viewing the XML Source for an XSLT Transformation

For more information

This section demonstrated some of the major features of Stylus Studio's debug tools, including specialized windows for presenting call stack and variable information. For complete information on using the XSLT debugger, see Chapter 6Debugging Stylesheets.

 
Free Stylus Studio XML Training: