How to get HTML text in XML via XSL



It looks like exclude-result-prefixes does not apply to xsl:copy-of. When I run following XML, its output has namespace on <table> tag which is not the desired behavior in my case. The ultimate goal is getting DataItem element which may contain XML/HTML type of text and should not be modified for any reason. So what is the best approach to get DataItem as it is?


XML



<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="test.xsl" ?>
<root>
<E2ETraceEvent xmlns="http://ift.tt/1leiCHa">
<ApplicationData>
<TraceData>
<DataItem>
<table>
<tr>
<td>This should not be a table</td>
<td>It must be a text</td>
</tr>
</table>
</DataItem>
</TraceData>
</ApplicationData>
</E2ETraceEvent>
</root>


XSL



<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://ift.tt/tCZ8VR"
xmlns:te="http://ift.tt/1leiCHa"
exclude-result-prefixes="te">
<xsl:output method="html" indent="no"/>
<xsl:template match="/">
<html>
<body>
<table>
<thead>
<tr>
<td>Data</td>
</tr>
</thead>
<tbody>
<xsl:for-each select="//te:E2ETraceEvent">
<tr>
<td>
<table>
<xsl:for-each select=".//te:TraceData//te:DataItem">
<tr>
<td>
<xmp>
<xsl:copy-of select="*" />
</xmp>
</td>
</tr>
</xsl:for-each>
</table>
</td>
</tr>
</xsl:for-each>
</tbody>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>


Output



<table xmlns="http://ift.tt/1leiCHa">
<tr>
<td>This should not be a table</td>
<td>It must be a text</td>
</tr>
</table>


Desired Output



<table>
<tr>
<td>This should not be a table</td>
<td>It must be a text</td>
</tr>
</table>

No comments:

Post a Comment