扫一扫
分享文章到微信
扫一扫
关注官方公众号
至顶头条
作者:廖煜嵘编译 来源:天极开发 2007年11月6日
关键字: Windows
<%@ 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("App_Data/Category.xsl"); XslCompiledTransform transform = new XslCompiledTransform(); transform.Load(xslPath); XsltArgumentList argsList = new XsltArgumentList(); string backGroundColor = "Tan"; //Add the required parameters to the XsltArgumentList object argsList.AddParam("BackGroundColor", "", backGroundColor); transform.Transform(xpathDoc, argsList, Response.Output); } } |
using System; public class DateTimeConverter { public DateTimeConverter() {} public string ToDateTimeFormat(string data, string format) { DateTime date = DateTime.Parse(data); return date.ToString(format); } } |
<?xml version="1.0" ?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:DateTimeConverter="urn:DateTimeConverter"> <xsl:output method="html" /> <xsl:param name="BackGroundColor" select="Blue" /> <xsl:template match="/"> <HTML> <HEAD> <TITLE>Invoking extension objects from an XSLT Style Sheet</TITLE> </HEAD> <BODY> <H2>Invoking extension objects from 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="DateTimeConverter:ToDateTimeFormat (ModifiedDate, 'F')" /> </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("App_Data/Category.xsl"); XslCompiledTransform transform = new XslCompiledTransform(); transform.Load(xslPath); XsltArgumentList argsList = new XsltArgumentList(); string backGroundColor = "Tan"; argsList.AddParam("BackGroundColor", "", backGroundColor); DateTimeConverter converter = new DateTimeConverter(); argsList.AddExtensionObject("urn:DateTimeConverter", converter); transform.Transform(xpathDoc, argsList, Response.Output); } } </script> |
如果您非常迫切的想了解IT领域最新产品与技术信息,那么订阅至顶网技术邮件将是您的最佳途径之一。
现场直击|2021世界人工智能大会
直击5G创新地带,就在2021MWC上海
5G已至 转型当时——服务提供商如何把握转型的绝佳时机
寻找自己的Flag
华为开发者大会2020(Cloud)- 科技行者