我得到了预期的输出 XML,其中部分 xml 在输出 xml 的末尾打印为纯文本。
我怎样才能在这里摆脱纯文本 xml?
输入 XML
<Coverage>
<CoverageInformation>
<IssueStateCT>AK</IssueStateCT>
<OptionCodeCT>ADR</OptionCodeCT>
<SegmentStatusCT>Frozen</SegmentStatusCT>
<ApplicationReceivedDate>09/18/2013</ApplicationReceivedDate>
<ApplicationSignedDate>09/10/2013</ApplicationSignedDate>
<CreationDate>09/17/2013</CreationDate>
<EffectiveDate>09/17/2013</EffectiveDate>
<IssueDate>09/17/2013</IssueDate>
<TerminationDate>09/16/2013</TerminationDate>
<RateSeriesDate>09/17/2013</RateSeriesDate>
</CoverageInformation>
<RiderInformation>
<IssueStateCT>AK</IssueStateCT>
<OptionCodeCT>ADR</OptionCodeCT>
<SegmentStatusCT>Frozen</SegmentStatusCT>
<ApplicationReceivedDate>09/18/2013</ApplicationReceivedDate>
<ApplicationSignedDate>09/10/2013</ApplicationSignedDate>
<CreationDate>09/17/2013</CreationDate>
<EffectiveDate>09/17/2013</EffectiveDate>
<IssueDate>09/17/2013</IssueDate>
<TerminationDate>09/16/2013</TerminationDate>
<RateSeriesDate>09/17/2013</RateSeriesDate>
</RiderInformation>
<RiderInformation>
<IssueStateCT>AK</IssueStateCT>
<OptionCodeCT>ADR</OptionCodeCT>
<SegmentStatusCT>Frozen</SegmentStatusCT>
<ApplicationReceivedDate>09/18/2013</ApplicationReceivedDate>
<ApplicationSignedDate>09/10/2013</ApplicationSignedDate>
<CreationDate>09/17/2013</CreationDate>
<EffectiveDate>09/17/2013</EffectiveDate>
<IssueDate>09/17/2013</IssueDate>
<TerminationDate>09/16/2013</TerminationDate>
<RateSeriesDate>09/17/2013</RateSeriesDate>
</RiderInformation>
</Coverage>
XSLT
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="CoverageInformation">
<SegmentVO>
<xsl:for-each select="*">
<xsl:copy>
<xsl:apply-templates/>
</xsl:copy>
</xsl:for-each>
<xsl:for-each select="../RiderInformation">
<SegmentVO>
<xsl:for-each select="*">
<xsl:copy>
<xsl:apply-templates/>
</xsl:copy>
</xsl:for-each>
</SegmentVO>
</xsl:for-each>
</SegmentVO>>
</xsl:template>
</xsl:stylesheet>
代码:
def w = new StringWriter()
TransformerFactory.newInstance()
.newTransformer( new StreamSource( new StringReader( xslt ) ) )
.transform( new StreamSource( new StringReader( xmlAsString ) ),
new StreamResult( w ) )
println groovy.xml.XmlUtil.serialize( w.toString() )
输出 XML
ERROR: 'Content is not allowed in trailing section.'
<?xml version="1.0" encoding="UTF-8"?>
<SegmentVO>
<IssueStateCT>AK</IssueStateCT>
<OptionCodeCT>ADR</OptionCodeCT>
<SegmentStatusCT>Frozen</SegmentStatusCT>
<ApplicationReceivedDate>09/18/2013</ApplicationReceivedDate>
<ApplicationSignedDate>09/10/2013</ApplicationSignedDate>
<CreationDate>09/17/2013</CreationDate>
<EffectiveDate>09/17/2013</EffectiveDate>
<IssueDate>09/17/2013</IssueDate>
<TerminationDate>09/16/2013</TerminationDate>
<RateSeriesDate>09/17/2013</RateSeriesDate>
<SegmentVO>
<IssueStateCT>AK</IssueStateCT>
<OptionCodeCT>ADR</OptionCodeCT>
<SegmentStatusCT>Frozen</SegmentStatusCT>
<ApplicationReceivedDate>09/18/2013</ApplicationReceivedDate>
<ApplicationSignedDate>09/10/2013</ApplicationSignedDate>
<CreationDate>09/17/2013</CreationDate>
<EffectiveDate>09/17/2013</EffectiveDate>
<IssueDate>09/17/2013</IssueDate>
<TerminationDate>09/16/2013</TerminationDate>
<RateSeriesDate>09/17/2013</RateSeriesDate>
</SegmentVO>
<SegmentVO>
<IssueStateCT>AK</IssueStateCT>
<OptionCodeCT>ADR</OptionCodeCT>
<SegmentStatusCT>Frozen</SegmentStatusCT>
<ApplicationReceivedDate>09/18/2013</ApplicationReceivedDate>
<ApplicationSignedDate>09/10/2013</ApplicationSignedDate>
<CreationDate>09/17/2013</CreationDate>
<EffectiveDate>09/17/2013</EffectiveDate>
<IssueDate>09/17/2013</IssueDate>
<TerminationDate>09/16/2013</TerminationDate>
<RateSeriesDate>09/17/2013</RateSeriesDate>
</SegmentVO>
</SegmentVO>
CT
AggPremium
IssuePendingPremium
08/15/2013
08/15/2013
08/05/2013
08/05/2013
09/19/2013
08/15/2013
09/20/2013
CT
AggPremium
IssuePendingPremium
08/15/2013
08/15/2013
08/05/2013
08/05/2013
09/19/2013
08/15/2013
09/20/2013