Directory - 1 Copy --2 Row - 3 Table - 4 Convert Form to CSV Files
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.
Because it is a swap line, just output the number of columns of the source table. Here, use
Cyclicity, in accordance with the number of columns in the first line (TR element). Use the following cycle
To take out the data to be saved in each line. Since the current node is TR [1] / TD, then use ../TD will only take the first row of TD elements. In order to remove all TD elements, it must be written into ../../tr/TD form.
The total number of new tables is saved in the variable x, and the number of rows currently being generated in the variable y is saved. 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>
A TD>
td>
C TD>
Ding TD>
glutulent td>
TR>
TD>
Geng TD>
Xin TD>
td>
td>
TR>
table>
body>
html>
Figure 2: Output page
3 table
The form can be seen 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).
Save the line number and column number to the variable row and column.
Use the ROW attribute output line number, the column property outputs the number.
xsl: attribute>
xsl: attribute>
When the program 3 is converted, the output is shown below.
XML Version = "1.0" encoding = "UTF-8"?>
Jia data>
< data>
C DATA>
Ding data>
glutulent data>
Hene data>
Geng data> Xin data>
data>
data>
databank>
4 Convert the form to a CSV file
Although XSLT is generally used to convert an XML document into an XML document, it is also possible to output a format other than an XML document. Below is an example of converting an HTML document containing the Table element into a CSV (program 5).
Since the converted object node is a TR element that represents a row, the template rule is defined for the TR element. If it is not the last element in the row, the separator ",".
, XSL: Text>
xsl: if>
The result of converting the program 3 is shown below.
A, B, C, Ding, glutama
Hehe, Geng, Xin,,
Note 1 The divided data format is separated between the individual data fields in the record.