In Books.xml
<?xml version="1.0"?>
<Books>
<Book>
<Title>Beginning XML</Title>
<Author>John</Author>
</Book>
<Book>
<Title>Mastering XML</Title>
<Author>Peter</Author>
</Book>
</Books>
In Books.xml
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="Books">
<HTML>
<BODY>
<TABLE>
<TR>
<TD>Title</TD>
<TD>Author</TD>
</TR>
<xsl:for-each select="Book">
<TR>
<TD><xsl:value-of select="Title"/></TD>
<TD><xsl:value-of select="Author"/></TD>
</TR>
</xsl:for-each>
</TABLE>
</BODY>
</HTML>
</xsl:template>
</xsl:stylesheet>
In Default.aspx Page
Add Xml icon From the toolbox
In Default.aspx.cs Page
//coding type 1
string xmlPath = Server.MapPath("Books.xml");
string xsltPath = Server.MapPath("Books.xslt");
XmlReader objXMlReader = XmlReader.Create(xmlPath);
XslCompiledTransform objXSLCompTransform =
new XslCompiledTransform();
objXSLCompTransform.Load(xsltPath);
StringBuilder objStrBuil = new StringBuilder();
TextWriter objTextWri = new StringWriter(objStrBuil);
objXSLCompTransform.Transform(objXMlReader, null, objTextWri);
Literal1.Text = objStrBuil.ToString();
objXMlReader.Close();
(Or)
//coding type 2
Xml1.DocumentSource = Request.QueryString[0];
Xml1.TransformSource = Request.QueryString[1];
No comments:
Post a Comment