首页 文章

WSO2 ESB在xslt中添加默认命名空间

提问于
浏览
1

我正在使用WSO2 ESB 4.8.1,我想使用xslt修改soap消息 .

我的肥皂消息:

<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
   <S:Body>
      <ns2:getResponse xmlns:ns2="http://nis.ayss.com.tr/">
         <return>
            <result>true</result>
            <responseList>
               <name>STACK</name>
               <number>001</number>
            </responseList>
         </return>
      </ns2:getResponse>
   </S:Body>
</S:Envelope>

我想将“name”元素更改为“brand”并修改此消息,如下所示:

<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
   <S:Body>
      <ns2:getResponse xmlns:ns2="http://nis.ayss.com.tr/">
         <return>
            <result>true</result>
            <responseList>
               <brand>STACK</brand>
               <number>001</number>
            </responseList>
         </return>
      </ns2:getResponse>
   </S:Body>
</S:Envelope>

XSLT:

<?xml version="1.0" encoding="UTF-8"?>

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:S="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:ns2="http://nis.ayss.com.tr/">

    <xsl:output method="xml" indent="yes"/>

    <xsl:template match="@*|node()">
        <xsl:copy>
                <xsl:apply-templates select="@*|node()"/>
        </xsl:copy>
    </xsl:template>

    <xsl:template match="name">
        <brand>
                <xsl:apply-templates select="@*|node()"/>
        </brand>
    </xsl:template>

</xsl:stylesheet>

我在WSO2 ESB中创建了一个xslt文件作为本地条目 . 但它添加了一个默认命名空间xmlns =“http://ws.apache.org/ns/synapse”并将xslt更改为:

<xsl:template match="name">
    <brand xmlns="http://ws.apache.org/ns/synapse">
            <xsl:apply-templates select="@*|node()"/>
    </brand>
</xsl:template>

所以我的结果肥皂消息是:

<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
   <S:Body>
      <ns2:getResponse xmlns:ns2="http://nis.ayss.com.tr/">
         <return>
            <result>true</result>
            <responseList>
               <brand xmlns="http://ws.apache.org/ns/synapse">STACK</brand>
               <number>001</number>
            </responseList>
         </return>
      </ns2:getResponse>
   </S:Body>
</S:Envelope>

如何在不使用WSO2 ESB中的XSLT添加命名空间的情况下修改此元素名称?

1 回答

  • 1

    在您的XSL本地条目中,将“brand”标记替换为xsl:element

    <xsl:template match="name">
            <xsl:element name="brand">
                    <xsl:apply-templates select="@*|node()"/>
            </xsl:element>
    </xsl:template>
    

相关问题