Your attempt completely disregards the (suboptimal) structure of your input XML. You need to create a row for each text node within the first NM_TORPCOLUMN_DATA
element, and populate its cells from the corresponding text nodes in all the NM_TORPCOLUMN_DATA
elements.
This is of course assuming that all NM_TORPCOLUMN_DATA
elements have exactly the same number of text nodes - otherwise I don't see how this task is possible at all.
XSLT 1.0
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:template match="/NM_TORP_TABLE">
<xsl:variable name="cols" select="NM_TORP_TABLE_LIST" />
<table border="1">
<!-- header -->
<tr>
<xsl:for-each select="$cols">
<th>
<xsl:value-of select="NM_TORP_LABEL"/>
</th>
</xsl:for-each>
</tr>
<!-- data -->
<xsl:for-each select="$cols[1]/NM_TORPCOLUMN_DATA/text()">
<xsl:variable name="row" select="position()" />
<tr>
<xsl:for-each select="$cols">
<td>
<xsl:value-of select="NM_TORPCOLUMN_DATA/text()[$row]"/>
</td>
</xsl:for-each>
</tr>
</xsl:for-each>
</table>
</xsl:template>
</xsl:stylesheet>
Applied to your input example, this will produce:
Result
<?xml version="1.0" encoding="UTF-8"?>
<table>
<tr>
<th>Nr.</th>
<th>Latitude</th>
<th>Longitude</th>
</tr>
<tr>
<td>1 </td>
<td>5° 10’ 6" S</td>
<td>107° 38’ 5" E</td>
</tr>
<tr>
<td>2 </td>
<td>3° 31’ 8" S</td>
<td>110° 4’ 4" E</td>
</tr>
<tr>
<td>3 </td>
<td>5° 19’ 7" S</td>
<td>109° 5’ 8" E</td>
</tr>
<tr>
<td>4 </td>
<td>3° 1’ 2" S </td>
<td>109° 50’ 2" E</td>
</tr>
<tr>
<td>5 </td>
<td>3° 9’ 6" S
</td>
<td>109° 47’ 4" E</td>
</tr>
<tr>
<td>6 </td>
<td>3° 20’ 9" S</td>
<td>108° 46’ 9" E</td>
</tr>
<tr>
<td>7 </td>
<td>5° 8’ 3" S </td>
<td>109° 52’ 4" E</td>
</tr>
<tr>
<td>8 </td>
<td>3° 55’ 9" S</td>
<td>107° 47’ 6" E</td>
</tr>
<tr>
<td>9
</td>
<td>4° 49’ 3" S</td>
<td>107° 42’ 3" E</td>
</tr>
<tr>
<td>10</td>
<td>4° 49’ 8" S</td>
<td>107° 42’ 2" E</td>
</tr>
<tr>
<td>11</td>
<td>3° 23’ 9" S</td>
<td>111° 35’ 24" E</td>
</tr>
<tr>
<td>12</td>
<td>4° 12’ 3" S</td>
<td>111° 32’ 1" E</td>
</tr>
<tr>
<td>13</td>
<td>4° 15’ 3" S</td>
<td>110° 43’ 5" E</td>
</tr>
<tr>
<td>14</td>
<td>4° 54’ 0" S</td>
<td>110° 46’ 2" E</td>
</tr>
<tr>
<td>15</td>
<td>3° 39’ 9" S</td>
<td>108° 32’ 9" E</td>
</tr>
<tr>
<td>16</td>
<td>5° 20’ 3" S</td>
<td>109° 11’ 3" E</td>
</tr>
</table>
Rendered
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…