In the example below we are trying to convert XML data into an HTML <table>
:
INPUT XML:
<?xml version="1.0" encoding="UTF-8"?>
<NM_TORP_TABLE>
<NM_TORP_TABLE_LIST>
<NM_TORP_LABEL>Nr.</NM_TORP_LABEL>
<NM_TORPCOLUMN_DATA>1 <BR/>2 <BR/>3 <BR/>4 <BR/>5 <BR/>6 <BR/>7 <BR/>8 <BR/>9
<BR/>10<BR/>11<BR/>12<BR/>13<BR/>14<BR/>15<BR/>16</NM_TORPCOLUMN_DATA>
</NM_TORP_TABLE_LIST>
<NM_TORP_TABLE_LIST>
<NM_TORP_LABEL>Latitude</NM_TORP_LABEL>
<NM_TORPCOLUMN_DATA>5° 10’ 6" S<BR/>3° 31’ 8" S<BR/>5° 19’ 7" S<BR/>3° 1’ 2" S <BR/>3° 9’ 6" S
<BR/>3° 20’ 9" S<BR/>5° 8’ 3" S <BR/>3° 55’ 9" S<BR/>4° 49’ 3" S<BR/>4° 49’ 8" S<BR/>3° 23’ 9" S<BR/>4° 12’ 3" S<BR/>4° 15’ 3" S<BR/>4° 54’ 0" S<BR/>3° 39’ 9" S<BR/>5° 20’ 3" S</NM_TORPCOLUMN_DATA>
</NM_TORP_TABLE_LIST>
<NM_TORP_TABLE_LIST>
<NM_TORP_LABEL>Longitude</NM_TORP_LABEL>
<NM_TORPCOLUMN_DATA>107° 38’ 5" E<BR/>110° 4’ 4" E<BR/>109° 5’ 8" E<BR/>109° 50’ 2" E<BR/>109° 47’ 4" E<BR/>108° 46’ 9" E<BR/>109° 52’ 4" E<BR/>107° 47’ 6" E<BR/>107° 42’ 3" E<BR/>107° 42’ 2" E<BR/>111° 35’ 24" E<BR/>111° 32’ 1" E<BR/>110° 43’ 5" E<BR/>110° 46’ 2" E<BR/>108° 32’ 9" E<BR/>109° 11’ 3" E</NM_TORPCOLUMN_DATA>
</NM_TORP_TABLE_LIST>
</NM_TORP_TABLE>
EXPECTED OUTPUT:
<table>
<tr>
<td>Nr.</td>
<td>Latitude</td>
<td>Longitude</td>
</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>
.......
</table>
XSLT CODE:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
exclude-result-prefixes="xs"
version="1.0">
<xsl:output method="html"/>
<xsl:template match="/">
<table>
<tbody>
<xsl:for-each select="NM_TORP_TABLE/NM_TORP_TABLE_LIST">
<tr>
<td><xsl:value-of select="NM_TORP_LABEL"/></td>
<td><xsl:value-of select="NM_TORPCOLUMN_DATA"/></td>
</tr>
</xsl:for-each>
</tbody>
</table>
</xsl:template>
</xsl:stylesheet>
Reference URL # https://xsltfiddle.liberty-development.net/nb9PtDU/1
question from:https://stackoverflow.com/questions/65889989/convert-xml-text-into-table