在
在
XsltCompileException
XsltException
先來看個簡單的例子
<?xml version=
<xsl:stylesheet version=
<xsl:output method=
<xsl:template match=
<HTML>
<HEAD>
<TITLE>Simple XSLT Transformation</TITLE>
</HEAD>
<BODY>
<H
<table border=
<center>
<xsl:for
<!
<xsl:element name=
<xsl:element name=
<xsl:value
</xsl:element>
<xsl:element name=
<xsl:value
</xsl:element>
<xsl:element name=
<xsl:attribute name=
<xsl:value
</xsl:element>
</xsl:element>
</xsl:for
</center>
</table>
</BODY>
</HTML>
</xsl:template>
</xsl:stylesheet>
然後其展示的ASPX代碼為
<%@ Page Language=
<%@ Import Namespace=
<%@ Import Namespace=
<%@ Import Namespace=
<%@ Import Namespace=
<%@ Import Namespace=
<script runat=
void Page_Load(object sender
{
string connString = WebConfigurationManager
[
using (SqlConnection connection = new SqlConnection(connString))
{
connection
SqlCommand command = new SqlCommand
(
XmlReader reader = command
XPathDocument xpathDoc = new XPathDocument(reader);
string xslPath = Server
XslCompiledTransform transform = new XslCompiledTransform();
transform
transform
}
}
</script>
其中注意我們先用xmlreader讀取數據庫提出來的數據(以xml auto的方式)
<?xml version=
<xsl:stylesheet version=
<xsl:output method=
<xsl:param name=
<xsl:template match=
<HTML>
<HEAD>
<TITLE>Passing Parameters to an XSLT Style Sheet</TITLE>
</HEAD>
<BODY>
<H
<table border=
<center>
<xsl:for
<!
<xsl:element name=
<xsl:attribute name=
<xsl:value
</xsl:attribute>
<xsl:element name=
<xsl:value
</xsl:element>
<xsl:element name=
<xsl:value
</xsl:element>
<xsl:element name=
<xsl:attribute name=
<xsl:value
</xsl:element>
</xsl:element>
</xsl:for
</center>
</table>
</BODY>
</HTML>
</xsl:template>
</xsl:stylesheet>
要注意的是其中的是
<xsl:attribute name=
<xsl:value
以這樣的形式指定了backgroundcolor是一個參數
當然
<%@ Page Language=
<%@ Import Namespace=
<%@ Import Namespace=
<%@ Import Namespace=
<%@ Import Namespace=
<%@ Import Namespace=
<script runat=
void Page_Load(object sender
{
string connString = WebConfigurationManager
[
using (SqlConnection connection = new SqlConnection(connString))
{
connection
SqlCommand command = new SqlCommand
(
XmlReader reader = command
XPathDocument xpathDoc = new XPathDocument(reader);
string xslPath = Server
XslCompiledTransform transform = new XslCompiledTransform();
transform
XsltArgumentList argsList = new XsltArgumentList();
string backGroundColor =
//Add the required parameters to the XsltArgumentList object
argsList
transform
}
} 其中
除此之外
using System;
public class DateTimeConverter
{
public DateTimeConverter()
{}
public string ToDateTimeFormat(string data
{
DateTime date = DateTime
return date
}
}
將這個類放在App_Code這個文件夾下
<?xml version=
<xsl:stylesheet version=
xmlns:xsl=
xmlns:DateTimeConverter=
<xsl:output method=
<xsl:param name=
<xsl:template match=
<HTML>
<HEAD>
<TITLE>Invoking extension objects from an XSLT Style Sheet</TITLE>
</HEAD>
<BODY>
<H
<table border=
<center>
<xsl:for
<!
<xsl:element name=
<xsl:attribute name=
<xsl:value
</xsl:attribute>
<xsl:element name=
<xsl:value
</xsl:element>
<xsl:element name=
<xsl:value
</xsl:element>
<xsl:element name=
<xsl:attribute name=
<xsl:value
(ModifiedDate
</xsl:element>
</xsl:element>
</xsl:for
</center>
</table>
</BODY>
</HTML>
</xsl:template>
</xsl:stylesheet>
在上面的代碼中
接下來
<%@ Page Language=
<%@ Import Namespace=
<%@ Import Namespace=
<%@ Import Namespace=
<%@ Import Namespace=
<%@ Import Namespace=
<script runat=
void Page_Load(object sender
{
string connString = WebConfigurationManager
[
using (SqlConnection connection = new SqlConnection(connString))
{
connection
SqlCommand command = new SqlCommand(
XmlReader reader = command
XPathDocument xpathDoc = new XPathDocument(reader);
string xslPath = Server
XslCompiledTransform transform = new XslCompiledTransform();
transform
XsltArgumentList argsList = new XsltArgumentList();
string backGroundColor =
argsList
DateTimeConverter converter = new DateTimeConverter();
argsList
transform
}
}
</script>
在上面的代碼中
From:http://tw.wingwit.com/Article/program/ASP/201311/21660.html