XML documents can only represent the content of data, while the actual data is to be presented on the webpage. You can use CSS to format the XML document and display it. this content has been described in detail in the previous article. In addition to CSS, there is also a language that can show XML data content on the webpage, that is, XSL. The XSL language includes XSLT (XSLTransformation) and FO (FormatObject ). XSLT documents can convert XML documents into other documents, such as HTML and Text. FO is used to format the output. since W3C also forms a unified standard for FO, only the usage of XSLT is described here.
When using XSLT, the most important part is to select the XML node value and create a template. The tag used to create the template is Generally, this tag requires a match attribute to determine the XML nodes it matches. The label used to select the XML node value is This label requires the select attribute to determine the XML nodes it matches. Here is a simple example to illustrate the following XML document:
1
2
3
4
5
Xml application series
6. toddler7
2009-03-23
8
9
Code description: the first line is the declaration part of the XML file. The second line introduces the XSLT file. the type attribute indicates that the file type is text/xsl, and the href attribute points to an XSLT file, the file name is stylesheet. xslt. The third line is later than the XML document section. The following is the content of stylesheet. xslt:
1
2
3
456
The first XSLT file789
101112
13
14
15
16
Title | 17
Author | 18
Date | 19
2021
22
23
242526
272829
303132
333435
36
Code description: Because the XSLT document is still in XML format, the first line is the header declaration of XML; the second line is the XSLT version and namespace declaration, the label is the heel node of the XSLT document. Use Create a template. select = "/" indicates that the root node of the document is matched. Lines 4 to 11th are the HTML node information to be generated by this node, and the ninth line is A tag indicates an application template. select = "xml" indicates that the template to be called is a template that matches the XML node. this template appears in row 3. All the rows (except the 26th rows) are repeated and are not described too much. Row 3 shows the content of the name tag. Use IE to open the XML file. the displayed content is as follows:
In addition, XSLT supports process control, condition selection, cyclic processing, and element sorting. An example is provided below. the content of the XML document is as follows:
1
2
3
4
5
6
Web page and Web program design7. Wu Libing8
9
Machinery Industry Press
10
2009-01 1
11
16.50
12
13
14
15
Software engineering16 Deng Liangsong17
18
Xi'an Electronic Technology Press
19
2005-06-10
20
33.20
21
22
23
24
25
26
Camellia27 Zhong Ma28
29
Foreign Language Publishing House
30
2005-06-30
31
22.00
32
33
34
35
Dream of Red Mansions36. Cao Xueqin37
38
China Education Press
39
2005-09-06
40
55.00
41
42
43
44
The content of the bookListStyle. xslt file is as follows:
Book List
Color:
Blue
Category: Computer books
Category: Novels
Author:
Press:
Publication date:
Pricing:
RMB
Book List
No. |
Category |
Title |
Author |
Press |
Publication date |
Pricing |
|
|
|
|
|
|
|
The code is not analyzed here. please understand the code and write your own XSLT template. The running effect of this code is as follows:
The above section details the code case analysis of XSLT template conversion XML document. For more information, see other related articles in the first PHP community!