【问题标题】:How to use not function for complex child element in xpath如何对xpath中的复杂子元素使用not函数
【发布时间】:2014-09-16 06:57:03
【问题描述】:

我有如下消息,我希望删除 Response_OutputData 标签。 我使用了 xpath 而不是函数,但似乎不是函数魔法不适用于此

我的意见

 <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>

我的xpath是这样的

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

但它无法提供与上述相同的输出 我的预期输出是

<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>
               </MOP>
            </env:Payload>
         </env:hjEnvelope>
      </open:reponce>

我将如何使用 xpath 或 xquery 或 xslt 来实现这一点 任何人澄清这一点 提前致谢。

【问题讨论】:

  • Response_OutputData 不是hjEnvelope 的直接子代。尝试使用双斜杠://env:hjEnvelope//*[not(local-name()='Response_OutputData')]

标签: xml xslt xpath wso2 xquery


【解决方案1】:

我们可以像这样为“Response_OutputData”节点定义一些空模板:

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="@*|node()">
    <xsl:copy>
      <xsl:apply-templates select="@*|node()" />
    </xsl:copy>
</xsl:template>
<xsl:template match ="*[local-name()='Response_OutputData']">
</xsl:template>
</xsl:stylesheet>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-01-29
    • 2021-02-23
    相关资源
    最近更新 更多