我想将下面的代码转换为某些格式的XML代码,
XSLT转换的输入:
<soap:Envelope
xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/'>
<soap:Body>
<rejectQuoteXMLResponse
xmlns='http://xxx.group.com'>
<out>
<![CDATA[
<TFGCPLResultXMLDO>
<processInstanceName>reejectQuoteXML</processInstanceName>
<duration>0</duration>
<accumulatedNumberOfExceptions>0</accumulatedNumberOfExceptions>
<accumulatedNumberOfErrors>0</accumulatedNumberOfErrors>
<accumulatedNumberOfWarnings>0</accumulatedNumberOfWarnings>
<numOfExceptions>0</numOfExceptions>
<numOfErrors>0</numOfErrors>
<numOfWarnings>0</numOfWarnings>
<BusinessMessages>
<BusinessErrors/>
<BusinessWarnings/>
<BusinessGenericMessages/>
</BusinessMessages>
<requestedTransSuccessfulInd>true</requestedTransSuccessfulInd>
<modifySuccessfulInd>false</modifySuccessfulInd>
<copySuccessfulInd>false</copySuccessfulInd>
<responseXMLString>
<RejectPolicyRes>
<status>Success</status>
<message>Reject Policy successful</message>
</RejectPolicyRes>
</responseXMLString>
</TFGCPLResultXMLDO>
]]>
</out>
</rejectQuoteXMLResponse>
</soap:Body>
</soap:Envelope>
所需的输出:
<QuoteRejectRs>
<UserId>344758</UserId>
<QuoteDetails>
<QuoteNumber>PA-Q450000</QuoteNumber>
<Status>Success</Status>
<Message>Reject Policy successful</Message>
</QuoteDetails>
</QuoteRejectRs>
XSLT转换代码:
<!-- <xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:md1="http://http://xxx.group.com" xmlns:exsl="http://exslt.org/common"
exclude-result-prefixes="xs md1"
extension-element-prefixes="exsl"
version="2.0"> -->
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
exclude-result-prefixes="xs"
version="2.0">
<xsl:output method="xml" indent="yes"/>
<xsl:template match="/">
<!--XML Response for Quote Reject which tell request has been submitted with success or fail -->
<QuoteRejectRs>
<UserId></UserId>
<QuoteDetails>
<QuoteNumber></QuoteNumber>
<Status>
<xsl:value-of select="substring-before(substring-after(.,'Envelope/Body/TFGCPLResultXMLDO>'), '<Envelope/Body/TFGCPLResultXMLDO/responseXMLString/RejectPolicyRes/status')"/>
</Status>
<Message>
<xsl:value-of select="substring-before(substring-after(.,'Envelope/Body/TFGCPLResultXMLDO>'), '<Envelope/Body/TFGCPLResultXMLDO/responseXMLString/RejectPolicyRes/message')"/>
</Message>
<!-- <Status><xsl:value-of select="soap:Envelope/soap:Body/md1:rejectQuoteXMLResponse/md1:out/md1:status"/></Status><Message><xsl:value-of select="Envelope/Body/TFGCPLResultXMLDO/responseXMLString/RejectPolicyRes/message"/></Message>-->
</QuoteDetails>
</QuoteRejectRs>
</xsl:template>
</xsl:stylesheet>
我尝试并能够转换包含名称空间的XML(SOAP:XXX(,但无法转换包含CDATA的XML。
我已经尝试过,但得到了包含&amp; lt的响应;&amp; gt;格式。
这样,任何人都知道解决此类任务的解决方案。
您抱怨自己是
获得包含&amp; lt的响应;&amp; gt;格式。
这很容易修复。xsl:value-of
具有专门用于此目的的属性disable-output-escaping
,因此
<Status>
<xsl:value-of
select="substring-before(substring-after(.,'Envelope/Body/TFGCPLResultXMLDO>'), '<Envelope/Body/TFGCPLResultXMLDO/responseXMLString/RejectPolicyRes/status')"
disable-output-escaping="yes"/>
</Status>
<Message>
<xsl:value-of
select="substring-before(substring-after(.,'Envelope/Body/TFGCPLResultXMLDO>'), '<Envelope/Body/TFGCPLResultXMLDO/responseXMLString/RejectPolicyRes/message')"
disable-output-escaping="yes"/>
</Message>
应该做您似乎正在寻找的工作。
但是,我敦促您采取不同的方法。通过字符串函数分开并解析XML文本是个坏消息。您真正应该做的是将嵌入式XML解析为XML文档,然后转换。不幸的是,XSLT 1.0和2.0没有为此的标准机制,但是某些实现将其作为扩展,并且取决于您执行转换的方式,为此目的安装自己的扩展功能可能相对容易。或者,您可以将嵌入式XML提取为初步步骤,然后将其转换为。