| 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> |
![]() |
![]() | asp.net网站静态化 | 11-30 |
![]() | ASP.NET读取XML文件 | 11-19 |
![]() | ASP.NET关闭当前窗口同时打开一个新窗口 | 10-28 |
![]() | gridview中弹窗口(根据不同的条件,弹出 | 10-25 |
![]() | asp.net跳转页面的三种方法比较 | 09-25 |
![]() | ASP.NET定时自动更新页面的 | 05-13 |
![]() | ASP.NET移动开发之SelectionList控件 | 05-13 |
![]() | 在ASP.NET中上传图片并生成缩略图 | 03-26 |