在Data Power XSLT中将CDATA转换为XML

时间:2014-07-08 16:01:47

标签: xml xslt

我有请求消息,其中必填字段在CDATA中,我需要检索这些字段并创建新请求并将其发送到数据电源中的Backend。

请求消息:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://example.com/456/" xmlns:soapenv1="http://example.com/ns1/CIP_Request.xsd">
    <soapenv:Header/>
    <soapenv:Body>
        <ns1:InqAccts>
            <ns1:reqxml>
                <![CDATA[<?xml version="1.0" encoding="utf-8"?><CIP_Request schemaVersion="3.0" xmlns="http://example.com/456/CIP_Request.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><UUID>97538E5A-ED0D-6A2F-97D86FE4DEEB6698</UUID><ClientCode>AND</ClientCode><InqDetails><AID>138716123</AID><CID>12345</CID><Desc>Sample</Desc></InqDetails></CIP_Request>]]></ns1:reqxml>
        </ns1:InqAccts>
    </soapenv:Body>
</soapenv:Envelope>

XSLT:

<xsl:stylesheet version="1.0" extension-element-prefixes="dp" exclude-result-prefixes="dp xalan" 
xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
xmlns:dp="http://www.datapower.com/extensions" 
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
 xmlns:ns1="http://example.com/456/" 
 xmlns:ns="http://output.com/123/" 
 xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

    <xsl:output method="xml" encoding="UTF-8" indent="yes"/>

    <xsl:variable name="result" select="//soapenv:Envelope/soapenv:Body/nao:InqAccts/nao:reqxml"/>

    <xsl:variable name="xmlResult">
        <dp:serialize omit-xml-decl="yes" select="//nao:reqxml" disable-output-escaping="yes" />
    </xsl:variable>

    <xsl:variable name="AID" select="$xmlResult//InqDetails/AID"/>
    <xsl:variable name="CID" select="$xmlResult//InqDetails/CID"/>
    <xsl:variable name="DESC" select="$xmlResult//InqDetails/Desc"/>

    <xsl:template match="/">
        <soapenv:Envelope>
            <soapenv:Header/>
            <soapenv:Body>
                <ns:DetailsGetRq>
                    <DetailAID>
                        <xsl:value-of select="$AID"/> 
                    </DetailAID>
                    <DetailCID>
                        <xsl:value-of select="$CID"/>
                    </DetailCID>
                    <desc>
                        <xsl:value-of select="$DESC"/>
                    </desc>
                </ns:DetailsGetRq>
            </soapenv:Body>
        </soapenv:Envelope>
    </xsl:template>

</xsl:stylesheet>

我正在寻找的转换请求是:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
 xmlns:ns1="http://example.com/456/" 
 xmlns:ns="http://output.com/123/" >
    <soapenv:Header />
    <soapenv:Body>
        <ns:DetailsGetRq>
            <DetailAID>138716123</DetailAID>
            <DetailCID>12345</DetailCID>
            <desc>Sample</desc>
        </ns:DetailsGetRq>
    </soapenv:Body>
</soapenv:Envelope>

我需要帮助将CDATA值解析为XML并从中检索字段值。

请让我知道哪种方法可以继续进行。

谢谢!

0 个答案:

没有答案