Visual Studio (2005+ versions), supports debugging of XSLT transformations (using breakpoints, watch windows and immediate windows).
XSLT Debugging Benefits;
a. Output construction of an XSL Transformation can be viewed step by step
b. Issues can be tracked with a very little effort, even with a very complex XSLT transformation
c. Developers can have a real time view of XSLT variables, elements and even complex XPath expression values with watch and immediate windows
d. Beginners can use this technique to learn XSLT and its execution flow from the ground up.
Debugging Steps:
1. Open Visual studio
2. Open your XSL file (File->Open->File->Open)
Fig1
3. Press F4, to open the property box for the selected XSL file. (Fig2)
4. Select an input XML file for XSL transformation, in the ‘input’ property (Fig2)
5. Provide the output XML file for the XSL transformation, in the ‘output’ property (Fig2)
Fig2
6. Now put breakpoints at desired locations in your XSL file (Fig3)
7. Start debugging using (Menu->XML->Start XSLT Debugging) - (Fig3)
Fig3
8. Your breakpoints will hit now. Open watch window or immediate window to evaluate XSLT variables, elements or even full XPath expressions. (Fig4)
Note: you can put all your XPath expressions in the watch window to view its actual value in the debugging context
9. Most Important! : You can see the step by step construction of the XSL Transformation output (in this case it will be the output XML File) - (Fig4)
(Fig4)
10. Have attached the input XML and XSL files used in the examples. You can try it on your own.
Recommendations:
a. Wherever possible try to use XSLT, for transforming XML’s. This is one of the most efficient, clean and high performing approach for transforming XML’s.
b. Use ‘XslCompiledTransform’ class, instead of the old ‘XslTransform’ class. Former uses compilation but latter uses interpretation.
No comments:
Post a Comment