如何删除响应部分中的复杂元素

时间:2014-09-15 12:59:12

标签: xslt xpath wso2 xquery

我是Usig wso2esb 4.8.1, 我希望使用xquery或xpath删除响应数据中的复杂元素。

 <soapenv:Body>
      <open:reponce xmlns:open="http://www.openuri.org/">
         <env:hjEnvelope xmlns:env="http://hj.mn.mw/Envelope">
            <env:UserId>as</env:UserId>
            <env:Sender>as</env:Sender>
            <env:MessageId>22195544</env:MessageId>
            <env:CorrelationId>1</env:CorrelationId>
            <env:GenTimeStamp>1</env:GenTimeStamp>
            <env:SentTimeStamp>1</env:SentTimeStamp>
            <env:Payload>
               <MOP xmlns="http://hj.mn.mw/MOP" xmlns:ns2="http://www.openuri.org/">
                  <Response>
                     <Result_OutputData>
                        <resultCode>0</resultCode>
                        <reference_ID>90</reference_ID>
                     </Result_OutputData>
                     <Response_OutputData>
                        <SystemName>google</SystemName>
                        <InterfaceName>nip</InterfaceName>
                        <ResultCode>0</ResultCode>
                        <ResultMessage/>
                        <ReferenceID>90</ReferenceID>
                     </Response_OutputData>
                  </Response>
               </MOP>
            </env:Payload>
         </env:hjEnvelope>
      </open:reponce>
   </soapenv:Body>
</soapenv:Envelope>

我希望删除我尝试使用此xpath属性的Response_OutputData标记

//*[not(local-name()='Response_OutputData')]

但它无法正常工作。即使我尝试使用我的xquery也无法正常工作

Xquery更改

<x xmlns="http://ws.apache.org/ns/synapse">
declare namespace soapenv = "http://schemas.xmlsoap.org/soap/envelope";
declare namespace soap="http://schemas.xmlsoap.org/soap/envelope/";
declare namespace open="http://www.openuri.org/";
declare namespace env="http://eai.bo.mw/Envelope";
declare variable $Response as document-node() external;
declare variable $hjEnvelope as document-node() external;
element{'open:reponce'}{
element{'env:hjEnvelope'}{$hjEnvelope//env:hjEnvelope/*[not(local-name()='Payload')],
element{'env:Payload'}{
$Response//soap:Body/*[1]/*[not(local-name()='Response_OutputData')]
    }}
    }

我如何删除此响应的复杂元素

1 个答案:

答案 0 :(得分:0)

您需要执行标识转换,其中除了您要跳过的元素之外,还要复制从输入到输出的所有内容。例如:

xquery version "1.0";

declare namespace soapenv = "http://schemas.xmlsoap.org/soap/envelope";

declare function local:filter($nodes as node()*, $names as xs:string+) {
    for $n in $nodes
    return
        typeswitch($n)
            case element() return
                if(not(local-name($n) = $names))then
                    element {node-name($n)} {
                        local:filter($n/(@*|child::node()), $names)
                    }
                else()

            default return
                $n
};


local:filter(/soapenv:body, ("Response_OutputData"))