![Phân tích tư tưởng của nhân dân qua đoạn thơ: Những người vợ nhớ chồng… Những cuộc đời đã hóa sông núi ta trong Đất nước của Nguyễn Khoa Điềm](https://timtailieu.net/upload/document/136415/phan-tich-tu-tuong-cua-nhan-dan-qua-doan-tho-039-039-nhung-nguoi-vo-nho-chong-nhung-cuoc-doi-da-hoa-song-nui-ta-039-039-trong-dat-nuoc-cua-nguyen-khoa-136415.jpg)
Transforming a DataSet Using XSLT
Số trang: 4
Loại file: pdf
Dung lượng: 16.53 KB
Lượt xem: 18
Lượt tải: 0
Xem trước 2 trang đầu tiên của tài liệu này:
Thông tin tài liệu:
[ Team LiB ] Recipe 8.7 Transforming a DataSet Using XSLT Problem You need to use an XSLT stylesheet to transform the contents of a DataSet. Solution Create an XslTransform object and call the Transform( ) method.
Nội dung trích xuất từ tài liệu:
Transforming a DataSet Using XSLT [ Team LiB ]Recipe 8.7 Transforming a DataSet Using XSLTProblemYou need to use an XSLT stylesheet to transform the contents of a DataSet.SolutionCreate an XslTransform object and call the Transform( ) method.Youll need to add the Microsoft Web Browser control to the Toolbox from the COM tabin the Customize Toolbox Dialog. Youll also need a reference to the Microsoft HTMLObject Library from the COM tab in Visual Studio .NETs Add Reference Dialog.Example 8-10 uses one XML file:Category.xslt The XSLT stylesheet used to transform the XML for the Categories table in the DataSet into HTML displaying the Categories data in an HTML table. The contents of this XML file are shown in Example 8-10.The sample code contains three event handlers:Form.Load Sets up the sample by filling a DataSet with the Categories table from Northwind.Transform Button.Click Initializes a WebBrowser control. Once the control is initialized, the DocumentComplete event is raised. The handler for the DocumentComplete event completes the XSLT transformation.DocumentComplete Gets the XmlDataDocument for the DataSet, creates an XSLTransform class, and transforms the XML document using the XSLT stylesheet. The results are displayed both in the WebBrowser control and as XML.Example 8-10. File: Category.xslt Category ID Name Description The C# code is shown in Example 8-11.Example 8-11. File: XslTransformForm.cs// Namespaces, variables, and constantsusing System;using System.Configuration;using System.IO;using System.Xml;using System.Xml.Xsl;using System.Data;using System.Data.SqlClient;// Table name constantsprivate const String CATEGORIES_TABLE = Categories;private const String XSLTFILENAME = ConfigurationSettings.AppSettings[Project_Directory] + @Chapter 08\Category.xslt;private DataSet ds;// . . .private void XslTransformForm_Load(object sender, System.EventArgs e){ // Fill the Categories within a DataSet. SqlDataAdapter da = new SqlDataAdapter(SELECT * FROM Categories, ConfigurationSettings.AppSettings[Sql_ConnectString]); ds = new DataSet(CategoriesDS); da.Fill(ds, CATEGORIES_TABLE);}private void transformButton_Click(object sender, System.EventArgs e){ // Create parameters to create web browser. String url = about:blank; object flags = 0; object targetFrameName = String.Empty; object postData = String.Empty; object headers = String.Empty; // Must wait for the navigation to complete so use the // DocumentComplete event for the rest of the processing webBrowser.Navigate(url, ref flags, ref targetFrameName, ref postData, ref headers);}private void webBrowser_DocumentComplete(object sender, AxSHDocVw.DWebBrowserEvents2_DocumentCompleteEvent e){ // Apply the XML transformation storing results to StringWriter. XslTransform xslt = new XslTransform( ); xslt.Load(XSLTFILENAME); StringWriter sw = new StringWriter( ); xslt.Transform(new XmlDataDocument(ds), null, sw, (XmlResolver)null); // Load the results of the transformation into the web browser. mshtml.IHTMLDocument2 htmlDoc = (mshtml.IHTMLDocument2)webBrowser.Document; htmlDoc.body.innerHTML = sw.ToString( ); // Display the results of the transformation. resultTextBox.Text = sw.ToString( );}DiscussionExtensible Stylesheet Transformations (XSLT) evolved from the Extensible StylesheetLanguage (XSL). XSLT defines a standard for XML data transformation—parsing aninput XML document and converting it into a result XML document. One common usefor XSLT is to transform XML data returned from a middle tier component into one ormore result documents (often HTML) to support different user interface or devicerequirements. For more information about XSLT, see Microsofts MSDN Library.In .NET, the DataSet is synchronized with the XmlDataDocument. As a result, in somecases XML services can be used to access the XmlDataDocument to perform certainfunctionality more conveniently than could be accomplished using the DataSet directly.To use XSLT to transform the contents of a DataSet, create an XslTransform object andcall the Transform( ) method on that object, as shown in this example:XslTransform xslt = new XslTransform( );xslt.Load(XSLTFILENAME);StringWriter sw = new StringWriter( );xslt.Transform(new XmlDataDocument(ds), null, sw, (XmlResolver)null);The results of the transformation can be sent to a variety of output formats usingoverloaded versions of the Transform( ) method.[ Team LiB ]
Nội dung trích xuất từ tài liệu:
Transforming a DataSet Using XSLT [ Team LiB ]Recipe 8.7 Transforming a DataSet Using XSLTProblemYou need to use an XSLT stylesheet to transform the contents of a DataSet.SolutionCreate an XslTransform object and call the Transform( ) method.Youll need to add the Microsoft Web Browser control to the Toolbox from the COM tabin the Customize Toolbox Dialog. Youll also need a reference to the Microsoft HTMLObject Library from the COM tab in Visual Studio .NETs Add Reference Dialog.Example 8-10 uses one XML file:Category.xslt The XSLT stylesheet used to transform the XML for the Categories table in the DataSet into HTML displaying the Categories data in an HTML table. The contents of this XML file are shown in Example 8-10.The sample code contains three event handlers:Form.Load Sets up the sample by filling a DataSet with the Categories table from Northwind.Transform Button.Click Initializes a WebBrowser control. Once the control is initialized, the DocumentComplete event is raised. The handler for the DocumentComplete event completes the XSLT transformation.DocumentComplete Gets the XmlDataDocument for the DataSet, creates an XSLTransform class, and transforms the XML document using the XSLT stylesheet. The results are displayed both in the WebBrowser control and as XML.Example 8-10. File: Category.xslt Category ID Name Description The C# code is shown in Example 8-11.Example 8-11. File: XslTransformForm.cs// Namespaces, variables, and constantsusing System;using System.Configuration;using System.IO;using System.Xml;using System.Xml.Xsl;using System.Data;using System.Data.SqlClient;// Table name constantsprivate const String CATEGORIES_TABLE = Categories;private const String XSLTFILENAME = ConfigurationSettings.AppSettings[Project_Directory] + @Chapter 08\Category.xslt;private DataSet ds;// . . .private void XslTransformForm_Load(object sender, System.EventArgs e){ // Fill the Categories within a DataSet. SqlDataAdapter da = new SqlDataAdapter(SELECT * FROM Categories, ConfigurationSettings.AppSettings[Sql_ConnectString]); ds = new DataSet(CategoriesDS); da.Fill(ds, CATEGORIES_TABLE);}private void transformButton_Click(object sender, System.EventArgs e){ // Create parameters to create web browser. String url = about:blank; object flags = 0; object targetFrameName = String.Empty; object postData = String.Empty; object headers = String.Empty; // Must wait for the navigation to complete so use the // DocumentComplete event for the rest of the processing webBrowser.Navigate(url, ref flags, ref targetFrameName, ref postData, ref headers);}private void webBrowser_DocumentComplete(object sender, AxSHDocVw.DWebBrowserEvents2_DocumentCompleteEvent e){ // Apply the XML transformation storing results to StringWriter. XslTransform xslt = new XslTransform( ); xslt.Load(XSLTFILENAME); StringWriter sw = new StringWriter( ); xslt.Transform(new XmlDataDocument(ds), null, sw, (XmlResolver)null); // Load the results of the transformation into the web browser. mshtml.IHTMLDocument2 htmlDoc = (mshtml.IHTMLDocument2)webBrowser.Document; htmlDoc.body.innerHTML = sw.ToString( ); // Display the results of the transformation. resultTextBox.Text = sw.ToString( );}DiscussionExtensible Stylesheet Transformations (XSLT) evolved from the Extensible StylesheetLanguage (XSL). XSLT defines a standard for XML data transformation—parsing aninput XML document and converting it into a result XML document. One common usefor XSLT is to transform XML data returned from a middle tier component into one ormore result documents (often HTML) to support different user interface or devicerequirements. For more information about XSLT, see Microsofts MSDN Library.In .NET, the DataSet is synchronized with the XmlDataDocument. As a result, in somecases XML services can be used to access the XmlDataDocument to perform certainfunctionality more conveniently than could be accomplished using the DataSet directly.To use XSLT to transform the contents of a DataSet, create an XslTransform object andcall the Transform( ) method on that object, as shown in this example:XslTransform xslt = new XslTransform( );xslt.Load(XSLTFILENAME);StringWriter sw = new StringWriter( );xslt.Transform(new XmlDataDocument(ds), null, sw, (XmlResolver)null);The results of the transformation can be sent to a variety of output formats usingoverloaded versions of the Transform( ) method.[ Team LiB ]
Tìm kiếm theo từ khóa liên quan:
công nghệ thông tin kỹ thuật lập trình Oreilly Ado Dot Net Cookbook Ebook-Lib Transforming a DataSet Using XSLTTài liệu liên quan:
-
52 trang 441 1 0
-
Top 10 mẹo 'đơn giản nhưng hữu ích' trong nhiếp ảnh
11 trang 332 0 0 -
74 trang 310 0 0
-
96 trang 307 0 0
-
Báo cáo thực tập thực tế: Nghiên cứu và xây dựng website bằng Wordpress
24 trang 299 0 0 -
Đồ án tốt nghiệp: Xây dựng ứng dụng di động android quản lý khách hàng cắt tóc
81 trang 293 0 0 -
Tài liệu dạy học môn Tin học trong chương trình đào tạo trình độ cao đẳng
348 trang 291 1 0 -
Kỹ thuật lập trình trên Visual Basic 2005
148 trang 281 0 0 -
EBay - Internet và câu chuyện thần kỳ: Phần 1
143 trang 279 0 0 -
Tài liệu hướng dẫn sử dụng thư điện tử tài nguyên và môi trường
72 trang 275 0 0