XSLT Tutorial

 

Table of Contents

Debugging the Program

In this step you will add breakpoints to the program and "debug" it. Adding breakpoints lets you to run the program in chunks, making it easier to watch variables and view output as it is generated. Before you begin, ensure that line numbering is enabled in Komodo (View|View Line Numbers).

  1. Step In/Assign the XML input file If necessary, click on the "mailexport2html.xsl" tab in the editor. From the menu, select Debug|Step In (or <F11>). In the Debugging Options dialog box, specify "mailexport.xml" as the XML input file (unless the input file was assigned in the previous step). By assigning the XML input file to the XSLT program file, the Komodo editor will divide horizontally so that both files can be displayed. Also, when you run the transformation, the XML file will be selected by default as the input file.
  2. Start Debugging In the Debugging Options dialog box, click OK to start debugging.

Komodo Tip Debugger commands can be accessed from the Debug menu, by shortcut keys, or from the Debug Toolbar. For a summary of debugger commands, see Debugger Command List.

  1. Watch the debug process A yellow arrow on line 6 indicates the position in the XSLT file where the debugger has halted. Another yellow arrow on line 1 in the XML file indicates the processing point in the input file.
  2. View the Debug Variables tab On the Output Pane, click the Debug Variables tab. On the Locals tab, notice that the current Call Stack is the template in line 6 of the XSLT program. The Locals tab displays a nested data structure of all the nodes in the XML document.
  3. Set a breakpoint On the "mailexport2html.xsl" pane, click on the grey margin immediately to the left of the code on line 12. This will set a breakpoint, indicated by a red circle.

Komodo Tip Breakpoints can be set at any time. When the debugger is not running, breakpoints are displayed as green circles. When the debugger is running, they are displayed as red circles.

  1. Line 6: Step Out Select Debug|Step Out. The debugger will run until it encounters the breakpoint on line 12; if no breakpoint had been set, the debugger would run until the end of the program.
  2. Line 12: Step In Select Debug|Step In. Notice that the debugger jumps to line 33 of the XSLT program, and advances the pointer in the XML file to line 4. When the debugger processed line 12 (xsl:apply-templates), it looked for a template that matched the top node in the XML document (<EMAILCOMMENTS>). When no matching template was found, it proceeded to the next node in the XML document (<EMAIL>) and found a matching template on line 33.
  3. View the Debug Output tab The HTML tags on lines 7 to 11 of the XSLT program have been written to the Output Pane.
  4. View the Debug Variables tab Notice that the Call Stack displays the current template; previous templates can be selected from the drop-down list.
  5. Line 33: Step In Use the Step In command until the current-line pointer in the XSLT file is on line 20.
  6. Line 20: Step In Watch the Output Pane as you Step In line 21. The xsl:value-of statement will select the contents of the <SUBJECT> field on line 9 of the XML file and place it within the HTML tags on lines 19 and 21.
  7. Line 21: Step In Line 22 will call the template "formatEmail" on line 45. Continue to step in until line 49 has been processed. The "formatEmail" will be processed with the "address" parameter on line 46. This routine will process the contents of the <ORIGADDRESS> node in the XML document. In order to generate the hyperlink in the output HTML document, lines 48 and 49 concatenate the string "mailto:" with the contents of the <ORIGADDRESS> node.
  8. Stop the Debugger Select Debug|Stop to stop the Komodo debugger.

Top Previous Next