What do book bulbs think of e-books

Walkthrough: Debugging an XSLT Stylesheet

The steps in this walkthrough show how to use the XSLT debugger. Steps include showing variables, setting breakpoints, and stepping through the code. You can use the debugger to run code one line at a time.

In preparation for this walkthrough, first copy the two sample files to your local computer. One of the files is the stylesheet and the other is the XML file that we will use as input to the stylesheet. In this walkthrough, the stylesheet used finds any books that cost less than the average book price.

Note

The XSLT debugger is only available in the Visual Studio editions "Professional" and "Enterprise".

Start debugging

  1. Select in the menu file the path to open > file out.

  2. Find the file below-average.xsl, and choose to open out.

    The stylesheet opens in the XML editor.

  3. In the Document Properties window, click in the box input click the browse button ( ... ). (If the window properties does not appear, right-click anywhere in the open file in Notepad, then select properties out.)

  4. Find the file books.xml, and then select to open out.

    This defines the source document file that is used for the XSLT transformation.

  5. Set a breakpoint on line 12 of the file below-average.xsl firmly. There are several ways to do this:

    • In line 12, click on the edge of the editor.

    • Click anywhere on row 12, and then press F9.

    • Right-click the startup tag, and then select Breakpoint > Insert breakpoint out.

  6. Select on the menu bar XML > Start XSLT debugging off (or press OLD+F5).

    The debug process will start.

    In the editor, the debugger is located on the element of the stylesheet. Another file called below-average.xml opens in the editor. This is the output file that will be populated while each node is in the input file books.xml are processed.

    The window automobile, Local and Monitor 1 appear at the bottom of the Visual Studio window. In the window Local all local variables are displayed with their current values. This includes the variables defined in the stylesheet as well as variables that the debugger uses to track the nodes that are currently in context.

Monitoring window

We add the window Monitor 1 add two variables so we can check their values ​​when the input file is processed. (You can also use the window Local to check values ​​if the variables to be monitored already exist.)

  1. Select in the menu Debug the path window > monitoring > Monitor 1 out.

    The window Monitor 1 is displayed.

  2. Enter in the field Surname then press the ENTER.

    The value of the variable is in the field value displayed.

  3. On the next line, type in the field Surname then press the ENTER.

    is an XPath expression that evaluates the current context node. The value of the -XPath expression is the first book node. This changes in the course of the transformation.

  4. Expand the node, and then expand the node with the value.

    You can view the value of the book price for the current book node and compare it to the value. Since the book price is below average, the condition should be met before you continue debugging.

Step through the code

  1. Press F5, to continue.

    Since the first book node fulfills the condition, the book node becomes the output file below-average.xml added. The debugger continues until it is back at the element in the stylesheet. The debugger is now on the second book account in the file books.xml.

    In the window Monitor 1 changes the value in the second book node. By evaluating the value for the price element, you can see that the price is above average and, as a result, the condition fails.

  2. Press F5, to continue.

    Since the second book node does not meet the condition, the book node does not become an output file below-average.xml added. The debugger continues until it is back at the element in the stylesheet. The debugger is now on the third node in the file books.xml.

    In the window Monitor 1 the value is changed to the third book node. By evaluating the value for the element, you can see that the price is below average. The condition should be met.

  3. Press F5, to continue.

    Since the condition was met, the third book becomes the output file below-average.xml added. All books in the XML document have been processed and the debugger will exit.

Sample files

The walkthrough uses the following two files.

below-average.xsl

books.xml

See also

Is this page helpful?