【发布时间】:2020-05-17 16:56:36
【问题描述】:
我需要禁用输出转义并删除 XML 定义的出现,即 xml version="1.0" encoding="UTF-8"?>
输入数据:
<ns1:outSystemWSResponse xmlns:ns1='http://abcd.co.za'
xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/' xmlns:xsd='http://www.w3.org/2001/XMLSchema'
xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'>
<ns1:out><?xml version="1.0" encoding = "UTF-8"?><PQR>
<STU>
<TEST1>Pen</TEST1>
<TEST2>Table</TEST2>
</STU>
</PQR></ns1:out>
</ns1:outSystemWSResponse>
预期输出
<?xml version="1.0" encoding="UTF-8"?>
<ns1:outSystemWSResponse xmlns:ns1="http://abcd.co.za"
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<ns1:out>
<PQR>
<STU>
<TEST1>Pen</TEST1>
<TEST2>Table</TEST2>
</STU>
</PQR>
</ns1:out>
</ns1:outSystemWSResponse>
我尝试使用以下 XSLT,但不确定如何删除 xml version="1.0" encoding="UTF-8"?>。请帮忙
<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:strip-space elements="*"/>
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="ns:out" xmlns:ns="http://abcd.co.za">
<xsl:copy>
<xsl:value-of select="." disable-output-escaping="yes"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
【问题讨论】: