繁体   English   中英

如何将标签添加到肥皂XML消息

[英]How to add tag to soap XML Message

我正在使用数据能力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

如何在标签前后添加内容

您可以使用以下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>

<xsl:template match="soap:Body">将创建新元素并复制<data>元素

您也可以使用下面的代码来复制其值。

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM