2.3 Process Parsing
If you successfully see the effect, you may want to know the specific meaning of these codes, let us explain in detail: Look at the hello.xsl file
<?xml version= "1.0" encoding= "Iso-8859-1"?>
This is the first line of code for a standard XML document, because XSLT itself is also an XML document. The encoding attribute is used to define the encoding used for the document, and iso-8859-1 mainly supports language encoding in Western Europe and North America. If you want to use Simplified Chinese, then you should write:
<?xml version= "1.0" encoding= "GB2312"?>
The next code is:
<xsl:stylesheet
Xmlns:xsl= "Http://www.w3.org/1999/XSL/Transform"
Version= "1.0" >
This is the first line of code for the standard XSLT file. The Xsl:stylesheet code means that the document is processed as a stylesheet (stylesheet). The Xmlns:xsl property is a namespace declaration, which, like the namespace usage method in XML, is used to prevent element name duplication and confusion. Where prefix xsl means that the elements used in the document conform to the XSLT specification of the consortium. The final version attribute shows that the stylesheet only uses XSLT
1.0 standard functionality, which is currently the only standard.
<xsl:template match= "/" >
A <xsl:template> element defines a template rule. The attribute Match= "/" describes the starting point of the template rule action in the XML source document. "/" is an XPath syntax, which we'll cover in more detail, where "/" represents the root of the XML structure tree.
The next code is:
<title>first XSLT example</title>
<body>
<p><xsl:value-of select= "Greeting"/></p>
</body>
Description: When the template rules are triggered, the contents of the template control the output results. In the example, most of the template content consists of HTML elements and text. Only the <xsl:value-of> element is the XSLT syntax, where the function of <xsl:value-of> is to copy the value of one node in the original document to the output document. The Select property specifies the node name to be processed in detail. This is the XPath syntax, and "greeting" means to look for elements with the root node named greeting and to process the node with a template. The specific is to find the <greeting> element, and then the element's value "Hello"
World "Copy to output file by template style.
Tip: Because the XML document is a strict hierarchy (see XML Files with IE5, there are similar multilevel associative menus in XML documents), we image the XML document as a document tree, where each pair of elements is called a node of the tree. The root element is the root node.
Finally close all elements:
</xsl:template>
</xsl:stylesheet>
Okay, here's the illustration. Have you ever wondered why you should use such a complex method to show "Hello World"?
The key is not the surface, but the substance: in this way, Hello World can be extracted from XML documents and processed by various XSLT templates to output documents of different requirements. Let's look at the main uses of XSLT:
The purpose of 2.4 XSLT
The main purpose of XSLT is Data transformation applications.
Because of the widespread popularization of xml-based E-business, XSLT is becoming more and more important as the role of data transformation. For example, directly convert the data format of TV news to the data format required by the newspaper news, transfer the stock data directly to the picture displayed on the Web page, and the EDI (Electronic data Interchange) data to be counted, sorted and so on.
XSLT is an ideal tool for dealing with similar work.