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