C # uses XSLT to convert an XML document to an HTML document

Source: Internet
Author: User
Tags xsl xslt

You need to reference the following namespaces:
UsingSystem.  XML;  UsingSystem.  Xml.  XSL;          
Method implementation:
Public Static String Convertxml(XmlDocument Inputxmldocument, String Xsltfilepath , XsltArgumentList Xsltargs) { System.Io.StringWriterSw= New System.Io.StringWriter(); XslCompiledTransformXsltrans= new  Xslcompiledtransform  Xsltrans. Loadxsltfilepath Xsltrans transform (inputxmldocument. Createnavigator xsltargs Sw);  return Sw. Tostring               /span>                

The sample XML file is as follows:

<?XML version="1.0"Encoding="Utf-8" ?><sexystars> <category Name="Bollywood"> <sexystar Name="Antra Mali" /> <sexystar Name="Deepika Padukone" /> <sexystar Name= "Mandira Bedi"  />  </category> <category name= "Hollywood" > < Sexystar name= "Jennifer Lopez"  /> <sexystar Span class= "ATN" >name= "Jessica Alba"  / > </category></sexystars                 

The sample XSLT file is as follows:

<?XML version="1.0"Encoding="UTF-8" ?><xsl:stylesheet Version="1.0" Xmlns:xsl="Http://www.w3.org/1999/XSL/Transform"><xsl:output Omit-xml-declaration="Yes"/> <xsl:template Match="Sexystars"> <div> <xsl:apply-templates Select="Category" /> </div> </xsl:template> <xsl:template Match="Category">  <xsl:value-of Select="@name"/>  <ul> <xsl:apply-templates select= "Sexystar"  / > </ul> </xsl:template>< Span class= "PLN" > <xsl:template match=  "Sexystar" > <li>  <xsl:value-of select = "@name" /> </li > </xsl:template></xsl: Stylesheet>               

C # code called by

:

xmldocument XDoc =new xmldocument (); Span class= "PLN" > Xdoc. Loadstring returnhtml =  Convertxml (xdoc, @< span class= "str" > "C:\SAMPLE.XSLT" , new Span class= "Typ" >xsltargumentlist ())           

The following HTML will be entered:

<div>Bollywood <ul> <li>antra mali</li> <li>deepika padukone</li> <li>mandira bedi</li> </ul> hollywood <ul> <li></li> <li></li> </ul></DIV>              

C # uses XSLT to convert an XML document to an HTML document

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.