【问题标题】:How to add tag to soap XML Message如何将标签添加到肥皂 XML 消息
【发布时间】:2013-09-23 14:09:47
【问题描述】:

我正在使用 datapower SOA

我有一个 XML :

<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Body>
<data>data</data>
</s:Body>
</s:Envelope>

我想把它改成:

<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Body>
<ns0:ReceptionRequest xmlns:ns0="ReceptionRequest">
<Message>
<data>data</data>
</Message>
</ns0:ReceptionRequest>
</s:Body>
</s:Envelope>

请帮助我处理 XSL

如何在标签前后添加一些东西

【问题讨论】:

    标签: xml xslt soap ibm-datapower


    【解决方案1】:

    您可以使用以下 XSLT:

    <?xml version="1.0" encoding="UTF-8"?>
    <xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns0="ReceptionRequest" exclude-result-prefixes="soap">
        <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
    
        <xsl:template match="@*|node()">
            <xsl:copy>
                <xsl:apply-templates select="node()" />
            </xsl:copy>
        </xsl:template>
    
        <xsl:template match="soap:Body">
            <xsl:copy>
                <ns0:ReceptionRequest xmlns:ns0="ReceptionRequest">
                    <Message>
                        <xsl:apply-templates />
                    </Message>
                </ns0:ReceptionRequest>
            </xsl:copy>
        </xsl:template>
    </xsl:stylesheet>
    

    &lt;xsl:template match="soap:Body"&gt; 将创建新元素并复制 &lt;data&gt; 元素

    【讨论】:

    • 如果我在 data 下有更多标签,它也会复制它们吗?
    • @alex:是的,它会复制“”元素中的所有元素
    • @alex 的答案满意吗?如果是,请接受答案
    【解决方案2】:

    你也可以使用下面的代码来复制它的值。

    <?xml version="1.0" encoding="UTF-8"?>
    
    <xsl:stylesheet version="2.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() = 'Body']">
    
          <xsl:copy>
          <ns0:ReceptionRequest xmlns:ns0="ReceptionRequest">
            <Message>
               <xsl:copy-of  select ="*[local-name() = 'data']"/>
    
            </Message>
        </ns0:ReceptionRequest>
         </xsl:copy>
       </xsl:template>
    
    
    </xsl:stylesheet>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-07-17
      • 2014-10-01
      • 1970-01-01
      • 2012-04-25
      • 1970-01-01
      • 2017-11-24
      相关资源
      最近更新 更多