VB.net 2010 视频教程 VB.net 2010 视频教程 python基础视频教程
SQL Server 2008 视频教程 c#入门经典教程 Visual Basic从门到精通视频教程
当前位置:
首页 > 网站开发 > ASPnet >
  • 在asp.net中使用<asp:xml>server control

            在asp.net中使用<asp:xml>server control
     首先我给出一个实例文件,之后我会通过它来介绍<asp:xml>server control
<html>
<body>
<asp:xml id="MyXml1" DocumentSource="Perf.xml" TransformSource="Perf.xsl" runat=server/>
</body>
</html>
Perf.xml:
<?xml version='1.0'?>
<sales>
<division id='North'>
<revenue>10</revenue>
<growth>9</growth>
<bonus>7</bonus>
</division>
<division id='South'>
<revenue>4</revenue>
<growth>3</growth>
<bonus>4</bonus>
</division>
<division id='West'>
<revenue>6</revenue>
<growth>-1.5</growth>
<bonus>2</bonus>
</division>
</sales>

Perf.xsl:

<xsl:stylesheet version='1.0' xmlns:xsl='http://www.w3.org/1999/XSL/Transform'>
<xsl:template match="/">
<style>
.value { width:"25%";font-family:courier new; font-size:.8em; white-space=pre;}
</style>
<table border="1" cellspacing="0" cellpadding="3" bordercolor="gainsboro">
<tr>
<th>Division</th>
<th>Revenue</th>
<th>Growth</th>
<th>Bonus</th>
</tr>
<xsl:for-each select='sales/division'>
<tr>
<td class="value"><em><xsl:value-of select='@id'/></em></td>
<td class="value"><xsl:value-of select='revenue'/></td>
<td class="value">
<xsl:if test='growth < 0'>
<xsl:attribute name='style'>
<xsl:text>color:red</xsl:text>
</xsl:attribute>
</xsl:if>
<xsl:value-of select='growth'/>
</td>
<td class="value"><xsl:value-of select='bonus'/></td>
</tr>
</xsl:for-each>
</table>
</xsl:template>
</xsl:stylesheet>
note:
<asp:xml>server控制元件有四个属性:
1.DocumentSource(xml文件路径)
2.TransformSource(xsl文件路径)
3.Document(引用一个XmlDocument对象)
4.Transform(引用一个XslTransform对象)
我们可以通过指定唯一的id控制<asp:xml>server元件
如果你有选择性的从数据库(sql或任意数据库)使用某些数据,你将通过dataset创建一个XmlDataDocument
下面的例子将很好的说明这一问题
<%@ Page ContentType="text/xml" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SQL" %>
<%@ Import Namespace="System.Xml" %>
<script language="VB" runat=server>
Function GetProductData() As DataSet
Dim connection as New SQLConnection("server=localhost;uid=sa;pwd=;database=northwind")
Dim command as New SQLDataSetCommand("SELECT * FROM Products WHERE ProductID<8", connection)
Dim dataset As New DataSet()
command.FillDataSet(dataset, "dataset")
Return dataset
End Function
Sub Page_Load(Sender as Object, E as EventArgs)
Dim DataSet1 as DataSet = GetProductData()
Dim XmlDoc as XmlDocument = New XmlDataDocument(DataSet1)
MyXml1.Document = XmlDoc
End Sub
</script>
<asp:xml id="MyXml1" runat=server/>


                      
 


相关教程