Edit online

Identify the XSLT / XQuery Expression that Generated Particular Output

To quickly spot the XSLT templates or XQuery expressions with problems, it is important to know what XSLT template in the XSLT stylesheet (or XQuery expression in the XQuery document) and what element in the source XML document generated a specified area in the output.

Some of the debugging capabilities (for example, Step in) can be used for this purpose. Using Step in, you can see how output is generated and link it with the XSLT/XQuery element being executed in the current source context. However, this can become difficult on complex XSLT stylesheets or XQuery documents that generate a large output.

You can click particular text in the Output view or XHTML output view and the editor will select the XML source context and the XSLT template/XQuery element that generated that text. Also, inspecting the whole stack of XSLT templates/XQuery elements that determined the state of the XSLT/XQuery processor at the moment of generating the specified output area speeds up the debugging process.

This is an example of a typical procedure for identifying an expression that generated particular output:

  1. Switch to the XSLT Debugger or XQuery Debugger perspective with one of the following actions:
    • Select Window > Open perspective > XSLT Debugger/XQuery Debugger or the XSLT Debugger/XQuery Debugger button in the top-right corner of the interface.
    • Select Document > XML Document > Debug scenario or use the Debug scenario action on the toolbar.. This action initializes the Debugger perspective with the parameters of the transformation scenario. Any modification applied to the scenario parameters (the transformer engine, XSLT parameters, transformer extensions, etc.) will be saved back in the scenario when exiting from the Debugger perspective.
  2. Select the source XML document in the XML source selector of the Control toolbar. In the case of XQuery debugging, if your XQuery document has no implicit source, set the source selector value to NONE.
  3. Select the XSLT/XQuery document in the XSL/XQuery selector of the Control toolbar.
  4. Select the appropriate engine in the XSLT/XQuery engine selector of the Control toolbar.
  5. Set XSLT/XQuery parameters using the Configure parameters button on the Control toolbar.
  6. Apply the XSLT stylesheet or XQuery transformation using the Run to end button that is available on the Control toolbar.
  7. Inspect the mapping by clicking a section of the output in either the Text tab or XHTML tab of the Output view.
    Figure 1. XHTML Output to Source Mapping
    Figure 2. Text Output to Source Mapping

    This action will highlight the XSLT / XQuery element and the XML source context. This XSLT template/XQuery element that is highlighted in the XSLT/XQuery editor represents only the top of the stack of XSLT templates/XQuery elements that determined the state of the XSLT/XQuery processor at the moment of generating the clicked output section. In the case of complex transformations, inspecting the whole stack of XSLT templates/XQuery elements speeds up the debugging process. This stack is available in the Output Mapping Stack view.