<?xml version="1.0" ?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output method="html" /> <xsl:template match="/"> <HTML> <HEAD> <TITLE>Simple XSLT Transformation</TITLE> </HEAD> <BODY> <H2>Simple XSLT Transformation</H2> <table border="1" cellSpacing="1" cellPadding="1"> <center> <xsl:for-each select="//Categories"> <!-- Each record on a seperate row --> <xsl:element name="tr"> <xsl:element name="td"> <xsl:value-of select="ProductSubcategoryID" /> </xsl:element> <xsl:element name="td"> <xsl:value-of select="Name" /> </xsl:element> <xsl:element name="td"> <xsl:attribute name="align">center</xsl:attribute> <xsl:value-of select="ModifiedDate" /> </xsl:element> </xsl:element> </xsl:for-each> </center> </table> </BODY> </HTML> </xsl:template> </xsl:stylesheet> |
<%@ Page Language="C#" %> <%@ Import Namespace="System.Data.SqlClient" %> <%@ Import Namespace="System.Xml" %> <%@ Import Namespace="System.Xml.Xsl" %> <%@ Import Namespace="System.Xml.XPath" %> <%@ Import Namespace="System.Web.Configuration" %> <script runat="server"> void Page_Load(object sender, System.EventArgs e) { string connString = WebConfigurationManager.ConnectionStrings ["adventureWorks"].ConnectionString; using (SqlConnection connection = new SqlConnection(connString)) { connection.Open(); SqlCommand command = new SqlCommand ("Select * from Production.ProductSubcategory as Categories " + " for xml auto,elements", connection); XmlReader reader = command.ExecuteXmlReader(); XPathDocument xpathDoc = new XPathDocument(reader); string xslPath = Server.MapPath("Category.xsl"); XslCompiledTransform transform = new XslCompiledTransform(); transform.Load(xslPath); transform.Transform(xpathDoc, null, Response.Output); } } </script> |
<?xml version="1.0" ?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output method="html" /> <xsl:param name="BackGroundColor" select="Blue" /> <xsl:template match="/"> <HTML> <HEAD> <TITLE>Passing Parameters to an XSLT Style Sheet</TITLE> </HEAD> <BODY> <H2> Passing Parameters to an XSLT Style Sheet</H2> <table border="1" cellSpacing="1" cellPadding="1"> <center> <xsl:for-each select="//Categories"> <!-- Each record on a seperate row --> <xsl:element name="tr"> <xsl:attribute name="bgcolor"> <xsl:value-of select="$BackGroundColor" /> </xsl:attribute> <xsl:element name="td"> <xsl:value-of select="ProductSubcategoryID" /> </xsl:element> <xsl:element name="td"> <xsl:value-of select="Name" /> </xsl:element> <xsl:element name="td"> <xsl:attribute name="align">center</xsl:attribute> <xsl:value-of select="ModifiedDate" /> </xsl:element> </xsl:element> </xsl:for-each> </center> </table> </BODY> </HTML> </xsl:template> </xsl:stylesheet> |
<xsl:attribute name="bgcolor"> <xsl:value-of select="$BackGroundColor" /> |