如何将标签添加到soap XML Message

时间:2013-09-23 14:09:47

标签: xml xslt soap ibm-datapower

即时通讯使用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

如何在标签之前和之后添加内容

2 个答案:

答案 0 :(得分:0)

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

答案 1 :(得分:0)

您也可以使用以下代码进行复制及其值。

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