Default. aspx
View code
<% @ Page Language = "C #" autoeventwireup = "true" codefile = "default. aspx. cs" inherits = "_ default" %> <! Doctype HTML public "-// W3C // dtd xhtml 1.0 transitional // en" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <HTML xmlns = "http://www.w3.org/1999/xhtml">
Background code
View code
protected void Page_Load(object sender, EventArgs e) { XmlDocument doc = new XmlDocument(); doc.Load(Server.MapPath("test.xml")); XslTransform trans = new XslTransform(); trans.Load(Server.MapPath("test.xsl")); Xml1.Document = doc; Xml1.Transform = trans; }
Test. xml
View code
<? XML version = "1.0" encoding = "UTF-8"?> <Publication> <book> <title> C # Full database system development manual </title> <pages> 628 </pages> </book> <title> Asp. net Program Development example book </title> <pages> 820 </pages> </book> </publication>
Test. XSL
View code
<? XML version = "1.0" encoding = "UTF-8"?> <XSL: stylesheet version = "1.0" xmlns: XSL = "http://www.w3.org/1999/XSL/Transform"> <XSL: template match = "/"> <HTML> <body> <! -- This Is An XSLT template file. fill in this area with the XSL elements which will transform your XML to XHTML. --> <Table width = "300" Height = "30" border = "10" cellspacing = "0" cellpadding = "0"> <tr align = "center"> <TD> title </TD> <TD> page number </TD> </tr> <XSL: for-each select = "publication/book"> <tr align = "center" Height = "30"> <TD> <XSL: value-of select = "title"/> </TD> <XSL: value-of select = "pages"/> </TD> </tr> </XSL: for-each> </table> </body>