How to generate an HTML file with XML – XSL in C #

Have you ever had to manipulate XML with XSL? Well here is a very simple way of how to manipulate both to perform the transformation of them to an HTML in C Sharp.

Assuming they have a project created to perform the necessary tests, we will create two classes that are the main one (which will contain the Main method inside them) and another class with the name “Convert_XML_XSL” (it can be renamed as you like), in the which will work most of the code.

Let’s start …

Step N ° 1: we will need to have the .xml and .xsl files as an introduction to the topic.

We create a file with the name and extension: “portfolio.xml” (Or as you like) where in its content we will paste this XML structure:

We create another file with the name and extension: “stocks.xsl” (or as you like) where in its content we will paste this XSL structure:

Step N ° 2: We will add the necessary libraries to the references in the “Convert_XML_XSL” class:

Step N ° 3: Now we will work our class “Convert_XML_XSL” in which we will include the following code next to its explanation before the XML library.

Step N ° 4: As a last step we will use our main class to make an instance of the class and use the method we have built.

Once each of the steps specified above is done we should obtain our HTML, in the example it is called “Result.html” and it will be located in the folder where we define it.

resultado

If everything turns out correctly, our result will be a table in HTML that will contain the data extracted from the .xml:

Greetings, see you later.

CC BY-NC-ND 4.0 How to generate an HTML file with XML – XSL in C # by QualityInfoSolutions is licensed under a Creative Commons Attribution-NonCommercial-NoDerivatives 4.0 International License.

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *

Contáctenos