我想从输入XML中删除转义字符。下面是我的输入XML
<?xml version="1.0" encoding="utf-8"?>
<AsBuiltWOEstimates_response>
<STATEMENT_TEST_response><xml_response>< header><wonum>20000000346</wonum><success>F</success></header><error><line></line> <message> LINE 1215 : Sub Account is null or blank : Work Order does not exist : Could not derive Business Segment from WO Header : Sub Account does not exist or is invalid ||</message></error></xml_response>
</STATEMENT_TEST_response>
</AsBuiltWOEstimates_response>
我已经尝试过XSLT删除字符,但是这样做也可以删除XML声明。因此它失败了,因为它无法识别它。
<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="no" omit-xml-declaration="yes"/>
<xsl:template match="/AsBuiltWOEstimates_response">
<xsl:value-of select="." disable-output-escaping="yes"/>
</xsl:template>
</xsl:stylesheet>
实际结果-
<header>
<wonum>20000000346</wonum>
<success>F</success>
</header><error>
<line></line>
<message> LINE 1215 : Sub Account is null or blank : Work Order does not exist : Could not derive Business Segment from WO Header : Sub Account does not exist or is invalid ||</message>
</error>
预期结果-
<?xml version="1.0" encoding="utf-8"?>
<AsBuiltWOEstimates_response>
<STATEMENT_TEST_response>
<header><wonum>20000000346</wonum><success>F</success></header><error><line></line> <message> LINE 1215 : Sub Account is null or blank : Work Order does not exist : Could not derive Business Segment from WO Header : Sub Account does not exist or is invalid ||</message></error>
</STATEMENT_TEST_response>
</AsBuiltWOEstimates_response>
答案 0 :(得分:1)
要获得预期的结果(大约在缩进方面),您应该这样做:
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:strip-space elements="*"/>
<!-- identity transform -->
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="xml_response">
<xsl:value-of select="." disable-output-escaping="yes"/>
</xsl:template>
</xsl:stylesheet>
答案 1 :(得分:-2)
<xsl:template match="node() | @*">
<xsl:copy>
<xsl:apply-templates select="node() | @*"/>
</xsl:copy>
</xsl:template>
<xsl:template match="xml_response">
<xsl:copy>
<xsl:value-of select="concat('<', substring-after(., '< '))" disable-output-escaping="yes"/>
</xsl:copy>
</xsl:template>
plz检查此代码,因为在'<'
之后的输入空间