Step 2: XSLT instances (3)

Source: Internet
Author: User
Tags xsl file xslt xslt example
2.3 process parsing if you successfully see the consequences, you may want to know the specific meaning of the code, let's explain in detail: look at the hello. xsl file? Xmlversion = "1.0" encoding = "iso-8859-1 "? This is the first line of code for the scale XML document.

2.3 Process Analysis


If you see the result of success, you may want to know the specific meaning of the code. let's explain it in detail: look at the hello. xsl file.



This is the first line of code for the scale XML document, because XSLT itself is also an XML document. The encoding attribute is used to define the encoding situation of the document application, ISO-8859-1 is important to support the language encoding of Western Europe and North America. If you want to use simplified Chinese, you should write it as follows:



The following code is:



Xmlns: xsl = 'http: // www.w3.org/5o/#/transform'

Version = '1. 0'>


This is the first line of code for the scale XSLT file. Xsl: stylesheet code refers to processing a document as a style sheet. Xmlns: The xsl attribute is a namespace declaration, which is the same as the namespace application method in XML to prevent duplication and confusion of element names. The prefix xsl indicates that the elements used in the document comply with W3C XSLT specifications. The last version attribute clarifies that the style sheet only uses XSLT
1.0 of the scale effect, which is the only scale currently.



One Element defines a template rule. Attribute match = '/' specifies the starting point of the template rule in the XML source document. '/' Is an XPath syntax, which will be detailed later. '/' here represents the root of the XML structure tree ).


The following code is:






First XSLT Example










Clarification: when the template rules are triggered, the template content will hold the output results. In this example, most of the template content consists of HTML elements and text. Only The element is the XSLT syntax. here The role is to copy the value of a node in the original document to the output document. The select attribute specifies the name of the node to be processed. This is the XPath syntax. 'greeting 'means to find the element whose root node name is greeting and process the node with a template. Specifically, find Element, and then set the value of the element 'Hello'
World 'Copy to the output file according to the template style.

Tip: Because the XML document is strictly hierarchical (you can view the XML file in IE5 and see the XML document similar to the multi-level association menu), the XML document in our image is called the document tree, each pair of elements is called a node of the tree. The root element is the root node.


Finally, close all elements:





Okay. The example is complete. Have you ever wondered why to display 'Hello world' in such a complicated way?

The key is not the surface, but the essence: With this method, hello world can be extracted from XML documents and processed using different XSLT templates to output documents with different requirements. Let's take a look at the important use of XSLT:



2.4 Use of XSLT


An important use of XSLT is the use of data conversion.

XML-based e-commerce is widely used, and XSLT is becoming increasingly important for data conversion. For example, the data structure of TV messages is directly converted into the data pattern required by newspaper messages, the stock data is directly converted into images displayed on the webpage, and EDI (electronic data exchange) data is statistically analyzed, sort and so on.

XSLT is a fantasy tool for processing similar jobs.




Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.