.NET Framework Developer's Guide  

The WriteXml method of the DataSet enables you to write the contents of a DataSet as XML data. A common task is to then transform that XML to another format using XSL Transformations (XSLT). However, synchronizing a DataSet with an XmlDataDocument enables you to apply an XSLT stylesheet to the contents of a DataSet without having to first write the contents of the DataSet as XML data using WriteXml.

The following example populates a DataSet with tables and relationships, synchronizes the DataSet with an XmlDataDocument, and writes a portion of the DataSet as an HTML file using an XSLT stylesheet. Following are the contents of the XSLT stylesheet.

对DataSet应用XSLT转换<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
对DataSet应用XSLT转换
对DataSet应用XSLT转换
<xsl:template match="CustomerOrders">
对DataSet应用XSLT转换  
<HTML>
对DataSet应用XSLT转换  
<STYLE>
对DataSet应用XSLT转换  BODY {font-family:verdana;font-size:9pt}
对DataSet应用XSLT转换  TD   {font-size:8pt}
对DataSet应用XSLT转换  
</STYLE>
对DataSet应用XSLT转换    
<BODY>
对DataSet应用XSLT转换    
<TABLE BORDER="1">
对DataSet应用XSLT转换      
<xsl:apply-templates select="Customers"/>
对DataSet应用XSLT转换    
</TABLE>
对DataSet应用XSLT转换    
</BODY>
对DataSet应用XSLT转换  
</HTML>
对DataSet应用XSLT转换
</xsl:template>
对DataSet应用XSLT转换
对DataSet应用XSLT转换
<xsl:template match="Customers">
对DataSet应用XSLT转换    
<TR><TD>
对DataSet应用XSLT转换      
<xsl:value-of select="ContactName"/><xsl:value-of select="Phone"/><BR/>
对DataSet应用XSLT转换    
</TD></TR>
对DataSet应用XSLT转换      
<xsl:apply-templates select="Orders"/>
对DataSet应用XSLT转换
</xsl:template>
对DataSet应用XSLT转换
对DataSet应用XSLT转换
<xsl:template match="Orders">
对DataSet应用XSLT转换  
<TABLE BORDER="1">
对DataSet应用XSLT转换    
<TR><TD valign="top"><B>Order:</B></TD><TD valign="top"><xsl:value-of select="OrderID"/></TD></TR>
对DataSet应用XSLT转换    
<TR><TD valign="top"><B>Date:</B></TD><TD valign="top"><xsl:value-of select="OrderDate"/></TD></TR>
对DataSet应用XSLT转换    
<TR><TD valign="top"><B>Ship To:</B></TD>
对DataSet应用XSLT转换        
<TD valign="top"><xsl:value-of select="ShipName"/><BR/>
对DataSet应用XSLT转换        
<xsl:value-of select="ShipAddress"/><BR/>
对DataSet应用XSLT转换        
<xsl:value-of select="ShipCity"/><xsl:value-of select="ShipRegion"/>  <xsl:value-of select="ShipPostalCode"/><BR/>
对DataSet应用XSLT转换        
<xsl:value-of select="ShipCountry"/></TD></TR>
对DataSet应用XSLT转换  
</TABLE>
对DataSet应用XSLT转换
</xsl:template>
对DataSet应用XSLT转换
对DataSet应用XSLT转换
</xsl:stylesheet>
对DataSet应用XSLT转换


The following code is the code to fill the DataSet and apply the XSLT style sheet.

Note   If the DataSet that you are applying an XSLT style sheet to contains relations, you will achieve best performance if you set the Nested property of the DataRelation to true for each nested relation. This allows you to use XSLT style sheets that implement natural top-down processing to navigate the hierarchy and transform the data, as opposed to using performance-intensive XPath location axes (for example, preceding-sibling and following-sibling in style sheet node test expressions) to navigate the data hierarchy. For more information on nested relations, see Nested DataRelations.
对DataSet应用XSLT转换[Visual Basic]
对DataSet应用XSLT转换
Imports System
对DataSet应用XSLT转换
Imports System.Data
对DataSet应用XSLT转换
Imports System.Data.SqlClient
对DataSet应用XSLT转换
Imports System.Xml
对DataSet应用XSLT转换
Imports System.Xml.Xsl
对DataSet应用XSLT转换


对DataSet应用XSLT转换[C#]
对DataSet应用XSLT转换
using System;
对DataSet应用XSLT转换
using System.Data;
对DataSet应用XSLT转换
using System.Data.SqlClient;
对DataSet应用XSLT转换
using System.Xml;
对DataSet应用XSLT转换
using System.Xml.Xsl;
对DataSet应用XSLT转换
对DataSet应用XSLT转换
public class Sample
}

相关文章:

  • 2021-08-10
  • 2021-08-06
  • 2021-12-19
  • 2021-10-19
  • 2022-03-09
  • 2021-11-19
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-10-05
  • 2021-10-25
  • 2022-01-12
  • 2021-06-04
相关资源
相似解决方案