As already mentioned, through XSL, we can submit the same data to the end customer in different data forms, an XSL file describes how the data is displayed, you can connect many XSL and the same XML document to provide different html-based representations, so in fact, We can build an xml-based desktop application. A graphical representation of the windows-based architecture is shown below:
There are two main advantages to this approach, first of all, you can operate the data in a platform and language independent way, and secondly, you can implement different view representations of the same data without the need for programming.
In fact, you need a tool that converts the original data into an XML formatted form and then represents it in HTML format. In fact, in IE5.0, you can implement different views of the data through its support for XSL. You can use the built-in XSL processor to produce output from an XML stream. Developers can write different XSL scripts and then process them with an XSL processor built in IE. On the other hand, we can transform the recordset into XML format through the intrinsic function implementation of the ADO component, the example code is as follows:
If Dir (xml_file) = "Then
Rs. Save Xml_file, adPersistXML
End If
Here the constant adPersistXML represents the use of an XML schema to save the contents of a recordset
Let's take a closer look at the Save method for the Recordset object, which is defined as follows:
Save ([FileName as String], [persistformat as PersistFormatEnum = ADPERSISTADTG])
Each parameter is optional, but when you first save the recordset to disk, you must specify the name of the file. If there is a valid filter when the method is executed, only the filtered data can be saved. The file is also automatically closed when the method close that calls the Recordset object closes the Recordset object. After the recordset is saved to disk, you can read it by using the Open method as follows:
Rs.Open "C:\myrs.xml"
Then we analyze the problem with the display of XML data, and IE5 's support for XSL is based on the most recent draft standards of the consortium. Here we discuss using VB to build an application that accesses data from a data source through an ADO interface. The resulting recordset can be presented in a different format. By writing an XSL document, you can arbitrarily add different views.
For example, once you have extracted a result set, you can use the DataGrid control in VB to easily display the data, the specific code is as follows:
Set rs = New ADODB. Recordset
Rs. CursorLocation = adUseClient
QueryString = "SELECT * FROM Employees"
Rs. Open QueryString, "Northwind" Northwind is a sample database of Microsoft, easily
' Access is found in SQL Server
Rs. ActiveConnection = Nothing
Set DataGrid1.DataSource = rs
In many cases, one view of this is not enough and you need to have strict control over each field. The records in the entire table may be expressed in both tables and trees, and providing multiple views makes the user feel more comfortable. The combination of XML and XSL is a good solution to this problem, and you can take advantage of the functionality of the WebBrowser control in IE5 to navigate directly.
The ADO component itself does not generate any XSL documents for the XML document it produces. This does not mean that you cannot write a generic XSL document yourself to change the way data is displayed. For example, to automatically display an XML document containing an ADO recordset in tabular form, you need to add the following code to the header of the XML document:
This simple.xsl file must be placed in the same directory as the XML document, it contains two nested loops, the first loop enumerates all the attributes of the element, whose names are displayed as headings in the first row, and the second loop to output all the records in the recordset.
The code for the simple.xsl file is indicated as follows:
The note here is the syntax for enumerating all the attributes of a given node, in fact we need to get all the attributes of any <z:row> element, and the string @* represents all the attributes (the name of a property always needs to precede with @, in order to use this value, <xsl: The value-of> node must set the properties that match it, expressed in @*.
By using the WebBrowser control as your engine for browsing data, you can use XML and XSL to separate content from the presentation layer. In this model, the role of XSL as a markup language (rather than a programming language) describes how to display XML data, and to add a new view, just add a corresponding XSL document. In fact, this web-based document/vision model can be compared with the document/view model under MFC.
Finally we need to talk about what is the difference between XSL and CSS? The key difference is that XSL is applied throughout the XML document, and CSS only has an effect on the display of HTML tags. XSL is a markup language that handles files, and CSS is a property collection that represents an attribute of an element in a markup language. Also, when XSL produces HTML output from an XML data stream, it can use CSS, and from the current point of view, they are two different technologies.
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.