1 Copy This is an example of copying all nodes (program 1). For example, from XHTML to XHTML or the like, the element can be slightly modified by most of the elements of the source and results, and the example can be modified, and only the part written code for the part needed. Program 1: Copy.xsl XML Version = "1.0"?> xsl: template> xsl: copy> xsl: template> xsl: stylesheet> Using the XSL: XCOPY element to recursively copy each node. 2 Lines Exchange This example can exchange the rows and columns of the HTML table (program 2).
Program 2: Table.xsl XML Version = "1.0"?> xsl: template>
Td> xsl: if> xsl: for-each> tr> < / xsl: for-each> xsl: copy> xsl: template> xsl: copy> xsl: template> xsl: styleSheet> Because it is Switching, so you can use only the lines of the number of columns in the source table. Here, use loop, and will be new (TR element) according to the number of columns (TR elements). Use the following cycle
Therefore, Use this condition to output data in the TD element. MOD is taken by the remainder. The page (program 3) shown in FIG. 1 will be converted, and the output result as shown in FIG. 2 can be obtained. Figure 1: Enter page
Program 3: Table.xml XML Version = "1.0"?>
Table title> head>
form h1>
1 td>
TD>
C TD>
Ding TD>
Penthen TD>
TD>
Geng TD>
Xin < / TD>
td>
td> tr> table> body> html>
Figure 2: Output page
3 Table table can be considered as a two-dimensional array. Let's try to convert it into a one-dimensional array. However, only the table content is placed, so we will keep the line number and the number of the original list as the result value (program 4). Program 4: Database = "1.0"?> dataBank> xsl: template> xsl: attribute> < XSL: COPY-OF SELECT = "$ color" /> xsl: attribute> data> xsl: for-each> xsl: for- Each> XSL: Template> xsl: styleSheet> Save the line number and the information information to the variable row and column. xsl: attribute> xsl: attribute> When the program 3 is converted, the output is as follows. XML Version = "1.0" encoding = "UTF-8"?> A data> Data> C data> Ding data> glutulent data> data> Geng data> Xin data> data> data> DATABANK> 4 Converts the table to the CSV file Although XSLT is generally converted to an XML document to an XML document, it is also possible to output a format other than the XML document. Below is an example of converting an HTML document containing the Table element into a CSV (program 5).