[Author: the universe of people] from this article you learned the most important thing is not just apply XSL style. When using an XML processor, the information in the XSL source document will be evaluated, rearranged, and then reassemble. We finally get a lovely version of XML data - but can be easily added, modified, and reordered flexible source information. This final product is called the result tree (RESULT TREE).
This is generated by a series of tests. Here is a simple example:
P> XSL: Template>
The first thing to explain is that the marker ended with "/" is empty. That is, the start of this type of marker does not take anything before the end of the marker. Similar examples in HTML are the tag. Since all information required for an image is included in a tag, there is no need to have end tag img>. The tissue XML document can accept empty markings, while the XSL style sheet must be an organization's good XML.
Let's go back to an example, it tells the XSL processor if you find a set of tag, you should separate the content and surrounded by
and p>. Or, if you want to show off your XSL knowledge, you can say "Add to the results tree."
This is a fairly simple test and is very typical. The content of the XML element is surrounded by performance information.
Now let's take a look at the complete example of the XSL style sheet written by the recipe.
Before I tell more XSL tags, I want to explain a problem that may be asked. Everyone knows that "P> itself in html is enough, then why should I use the endless p> marker?
Can someone answer? The answer is: There is no corresponding end tag, that part is not an organization's good XML, which will produce a fatal error. [Center] Section III: A XSL Style Table [/ Center] Below is a complete style sheet.
body> html> xsl: template>
's fabulous h1> xsl: template>
H2> xsl: template>
Eat for: h3> td>
h3> td> tr> table> xsl: template>
directions h4>
p> xsl: template> ingredients b> < / xsl: template> xsl: template> xsl: styleesheet> The result will not give me any Design award, but it is an XSL that can work. This may only explain only the following commands:
body> html> xsl: template>
The "/" of the first line tells the processor This node is applied to the root of the XML document. Thus, the commands in this section are the foundation of the results tree. The processor defendant puts the and
tag at the beginning and end of the document, and then processes or prints all sub-elements. Because it is the root element, it means "print all things."
Now, if you consider a few seconds, you will feel a bit weird. If the roots of the process-children command passes the source code to the results tree, all nodes that match the template can work with the source code that has been processed. However, the problem is that the XSL has a set of rules that determine which content being passed to the results tree, the most important rule is that the most specific match will win. Obviously, the form of the element name is more specific than the root layer. Therefore, all templates match nodes will transcend rules of the roots.
Note how easy it is to add HTML tags with XML data. When the XSL processor sees those markers that are not in the XSL vocabulary, they will pass them to the results tree. If you spend some time, you may find huge potential. XSL can be used as a conversion language. Data stored in an XML file can be converted to another with a completely different tag. Also, information can be modified to work with XML applications that can correspond to a different set of marker sets.
And not only these, if people expect, the style sheet can open and close with the matching tag, which is a set of well-organized units. Very good, but there are restrictions.
[Center] Section II: Select XSL [/ Center] Simple Not fully met our request. For example, I want to cancel the contents of the tag when the tag appears. In this case, I don't have to worry about "DINNER" and "APPETIZER" on the front surface. I may also want to adjust the layout by inserting a large number of blank in the last Ingredient.
Like some of the advertising parties: All of this is possible - more. SL has a tool for matching elements with their father members or sub-members. It also allows a position to match. For example, a specific format can be applied to the first and last particular elements, and the like.
Now let us consider some more complex things, such as the task of sweating in the dream. I need a list of recipe names and their ingredients. Now, if my web page is not connected to the database, I have to write a query statement. Because I am not very familiar with SQL, I need to get the DBA help. But if you know XSL, I will get rid of these troubles.
The result is not magical. But there will be no problem in the Table marker. Obviously, I store information in XML, but I think it is best to take a closer look.
The first line is familiar, but simply matches the template. But the second line is somewhat different - each of the recipe elements that appear in the element list, until the XSL: for-Each> tag. Then I started the HTML form, using the tag to output the contents of the Recipe_name element into the table unit. After closing the first table unit, things start cool. Next line () starts an additional nested loop, allowing me to output all Ingredient into the appropriate display information. The rest of the style sheet should be well understood.
But wait, I know you are thinking: "Is he said cool? What is this cool?"
The For-Each function is one of several programming features of XSL. There is also if-life and selection functions. These features allow anyone to easily manipulate the XML content in any manner (or at least a feasible manner). If you can achieve these features, it is cool.
[Center] Section 5: From Specification to Implementation [/ Center] Since you have seen some of the XML's features, then I want to propose a question: XML to these contents by separating the content into the well-organized and effective XML file What can't do it? As I am displayed in front, the data can be manipulated and then put it in the layout of your choice. Or data can be processed into a form that can be used by other applications. So, is there any other?
We will once again face the core of the extensibility. Once the data is defined, we can do anything you want to do. If we come to a time that can handle XML, spreadsheets, and performance programs, the same set of data can almost be used in any use.
But, hehe! This is still a dream.
We can only want the browser to implement these features, but we have no reason to optimize. Even if Tim Bray, XML's godfather also said that the Try to XSL can only be implemented after the CSS standard is fully implemented. Who knows when can I achieve it? And this is not the only problem.
XSL To exclude another barrier. The XSL specification has two distinct parts. The first part is the processing data structure we discussed here. Another part is a set of formatted objects for applying style. This part needs to do a lot of work. In my opinion, now I need a lot of people to do a lot. For example, there should be a command that is suitable for both screens and printouts. This specification will eventually be ultimately difficult to achieve, and end users are also difficult to implement this "unparalleled" attempt. But now, we can't do what - I can only pass our own happy little days, and I hope that my comrades who are responsible should be messy. Edit XML document online with XSL and ASP
[Author: the universe of people]
In this paper, a method of editing XML document data online is described herein. Since NetScape is relatively weak supporting XML, the processing of data must be performed on the server side. To edit the XML document, what you want to do is how to extract these data and display to visitors, XSL provides us with a good solution to our XML file. The following example is to display the XML document with the XSL style to the user to edit, and then submit the edited data to the server and update the data on the server. Here is an ASP (Active Server Pages) to complete our task.
First, load the XML document we want to edit, using Microsoft's document object model (Microsoft XMLDOM Object) and XSL, the XML document can be converted to the server side to the HTML file content that can be displayed on the client. Let's take a look at what we use the XML and XSL files. XML file: UserData.xml
XML Version = "1.0" encoding = "GB2312"?>
Value> Mencius Field_
Value>
field>
Value> Male Field_
Value>
field>
Value> China Network Technology Development Company Beijing Branch Field_
Value>
field>
Value> 102 layers of Beijing Kerry Center Field_
Value>
field>
Value> 1391139136 * field_
Value>
field>
Value> amxh@21cn.com field_
Value>
field>
User Information>
'
Www.knowsky.com
XSL file: UserData.xsl
XML Version = "1.0" encoding = "GB2312"?>
User Information Edit: h1>
Value-of select = "@ id" /> td>
Value-of select = "@ id" /> xsl: attribute>
Value-of select = "@ id" /> xsl: attribute>
Value "/> xsl: attribute> input>
td>
TR>
xsl: for-energy>
TABLE>
Value = "Complete Editing" />
form>
body>
html>
xsl: template>
xsl: stylesheet>
The XSL file uses the XSL: for-each element to traverse the entire XML file, "ID" attributes for each "Field" element in the XML file, and the "ID" and "Name" of the HTML form text input box. Thus, the text input box of the HTML form shows the element value of the XML file. This file is responsible for the transformation of the XML document in the server side so that it can be displayed on various browsers.
The following is a key program that implements the function of opening and updating the XML document, and decides whether it is updated according to the submission of the form. It contains two functions, LoadXMLFile is responsible for loading and converting the XML files to be displayed; UpdateXML functions are responsible for updating XML files.
Set objdom = Server.createObject ("Microsoft.xmldom")
'' Turn off the file asynchronous load mode.
Objdom.async = false
'' Load an XML file.
Objdom.Load Strxmlfile
'' Set the root element.
Set objRoot = objDom.documentelement
'' Traverse the Form collection and write the submitted data into the XML file.
For x = 1 to request.form.count
'' Check if the submitted data contains a button. If so, ignore this data.
IF INSTR (1, Request.Form.Key (x), "btn") = 0 THEN
'' Follow the XSL query mode to establish an objfield variable, corresponding to the elements of the form to the corresponding elements in the XML document [Field_
Value].
Set objfield = objRoot.selectsinglenode ("Field [@ ID = ''" & recommended.form.key (x) & "'] / field_
Value ")
'' Put the data submitted by the form and the node value in the XML document.
Objfield.text = request.form (x)
END IF
NEXT
'' Save the edited XML file.
Objdom.save strxmlfile
'' Release all references to objects.
Set objdom = Nothing
Set objRoot = Nothing
Set objfield = Nothing
'' Call the loadXmlfile function, display the new edited XML file with the UpdatedUserData.xsl style list to the client.
LoadXmlFile strXmlfile, server.mappath ("updatedUserData.xsl) End Function
'' Check if the form is successfully submitted, such as submitting, updating XML files; otherwise, go to the editing state.
When the form is submitted, we use UpdatedUserData.xsl to display the data we just edited.
UpdatedUserData.xsl is as follows:
XML Version = "1.0" encoding = "GB2312"?>
Updated user information is as follows: h1>
Value-of select = "@ id" />
td>
Value-of select = "field_
Value "/>
td>
TR>
xsl: for-energy>
TABLE>
Value = "Return"
Onclick = "history.go (-1)" />
form>
body>
html>
xsl: template>
xsl: stylesheet>
The above is just a simple example of XML cross-platform applications, combining specific needs, we can write more powerful programs to complete our more negative work. All programs are debugged in the Win98se PWS IE5.5 Netscape 4.75 Netscape 6 MSXML3.DLL environment.
Use XSL and ASP to retrieve and update XML file content
[Author: the universe of people]
With XML file storage data, you can realize a real cross-platform, which gives our data to achieve a lot of convenience. Examples of this article show you how to add, delete, and modify the XML files. For the convenience of the description, the "personal data" of everyone in this example is sometimes also recorded.
First, we list all the records of the XML file, then use the server-side ASP program and XSL style single file to display the XML file to the HTML file to display in any browser. Now suppose having a customer data file UserData.xml as follows:
The XSL style single file traverses the content of the entire XML file and uses HTML Table tag to display it. This allows the visitor to view the details of the customer by clicking the customer name, you can also add new customer information.
Below, we write UserData.asp programs to complete XML file conversion, data browsing, modification, deletion: