Debug XSLT in Visual Studio

Source: Internet
Author: User
Tags xsl xslt
XSLT (Extensible Stylesheet Language Transformation) is a language used to convert the XML document structure.
I believe you are no stranger to XML. It is a computer. Program HTML is a special XML, and XSLT is also an XML, but the former is used to display specific text information in a browser, the latter is used to format the data in XML and output the data in XML according to the requirements specified in the XSLT document. It is no exaggeration to say that XSLT is like CSS in HTML in XML. For more detailed introduction and use of XSLT, refer to the section on XSLT in w3school.
It is very convenient to develop and use XSLT in Visual Studio, thanks to Microsoft's XML control. which version of net was introduced, but since this control is available, it is very easy to load and format XML output in the program. There are a lot of XML controls on the Internet Article And the example, it looks like this: < ASP: XML ID = "Xmlcontent" Runat = "Server" Documentsource = "~ /XBRL. xml"   />

1 Xmlcontent. transformsource =   " ~ /XSL/incomestatement. XSLT " ;
2
3 Xmlcontent. transformargumentlist =   New System. xml. XSL. Pipeline targumentlist ();
4 Xmlcontent. transformargumentlist. addparam ( " Quarter " , String . Empty, currentquarter. number );
5 Xmlcontent. transformargumentlist. addparam ( " Year " , String . Empty, currentquarter. year );
6 Xmlcontent. transformargumentlist. addparam ( " Statementtype " , String . Empty, externaltable. tostring ());

In the XML control, you can directly use the documentsource attribute to specify the XML file to be loaded.CodeIn the preceding example, the background code is mainly used to pass three parameters to the XSLT file, this allows you to perform some judgment operations based on the values of these three parameters when parsing an XML file.
In general applications, when the XML file structure is simple, we can almost write our own scripts to complete all the formatting work, which is effortless! In addition, even if XSLT is used for parsing, problems can be easily modified. However, if the XML file to be parsed is very large and complex, for example, in XBRL (eXtensible Business Reporting Language, General Business Reporting Language), we usually need to use XSLT to parse the XBRL entity file, then, many complex enterprise financial statements are generated. If an error occurs at this time, it is difficult to visually observe the Code to find the error. Since XSLT can write code logic and support simple logic operations, can it be debugged? Just like debugging C # code!
There are many tools dedicated to debugging XSLT code on the Internet, but they are not ideal. In fact, Visual Studio provides a good XSLT debugger, which is integrated in the development environment and can be easily used for XSLT debugging.

 

XSLT is used to parse XML. It is enough to have these two files during debugging and does not need the actual running environment or page. There are two ways to start XSLT debugging. Apart from the two menu locations shown above, you can set breakpoints in the XML file or in the XSLT file, I prefer the latter because of the key points in the parsing process.AlgorithmAll are written in the XSLT file. It is most intuitive to directly set breakpoints to track the values of various variables in real time during debugging.
Click debug XSLT. If debugging is performed through an XML file, Visual Studio displays the select XSLT file dialog box. If debugging is performed through An XSLT file, visual Studio displays the select XML file dialog box. After selecting the file, XSLT starts to parse the corresponding XML file. If a breakpoint occurs, it stops. Then you can debug XSLT like debugging C # code.

The parsing result is displayed in the right window, and the final result should be a relatively complete HTML, depending on the definition in your XSLT file.
If you frequently encounter problems when writing complex XSLT files, you can use the debugging tool provided by Visual Studio to debug XSLT. I believe you can also compile a very powerful XSLT file, in this way, the XML file is parsed into different styles.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.