說明:以下代碼能原樣復制輸入XML的所有節點和屬性,雖說使用ESQL和JavaCompute很容易完成此任務。但是將以下代碼稍作修改,就可以對輸入進行篩選,剪裁和重構的工作。
輸入:
<a id="1"><b id="2">3</b></a>
代碼:
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="@*">
<xsl:attribute namespace="{namespace-uri()}" name="{name()}">
<xsl:value-of select="."/>
</xsl:attribute>
</xsl:template>
<xsl:template match="text()">
<xsl:value-of select="."/>
</xsl:template>
</xsl:stylesheet>
輸出:
<?xml version="1.0" encoding="UTF-8"?><a id="1"><b id="2">3</b></a>