2013-07-21 129 views
0

我想更改WSO2 ESB中的xml節點名稱,即。我有以下XML更改ESB中的xml節點名稱

<MessageStatus xmlns="foo.example.org">
<ErrorCode>$1</ErrorCode>
<Message>$2</Message>
</MessageStatus>

,我想這是這個

<ItemName xmlns="foo.example.org">
<ErrorCode>$1</ErrorCode>
<Message>$2</Message>
</ItemName>

隨着itemNames中的財產;我的意思是他們會動態變化。 有沒有什麼方法可以使用ESB Mediators進行更改?

回答

4

最後我這樣做是使用XSLT調解員,調解員我的配置是這樣的:

<xslt xmlns="http://ws.apache.org/ns/synapse" key="conf:/users/UsersXSLT.xslt"> 
    <property xmlns:ns="http://org.apache.synapse/xsd" name="TagName" expression="concat(get-property('OperationName'),'Response')"/> 
</xslt> 

我定義的屬性,這是我可以在我的XSLT轉換中使用它。 我的XSLT是:

<?xml version="1.0" encoding="ISO-8859-1"?> 
<xsl:stylesheet version="2.0" 
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
xmlns:fn="http://www.w3.org/2005/02/xpath-functions" 
xmlns="http://www.jdnasir.ac.ir/EMI/UserProxy/" 
exclude-result-prefixes="fn"> 
<xsl:output method="xml" omit-xml-declaration="yes" indent="yes"/> 

<xsl:template match="/"> 
<xsl:apply-templates /> 
</xsl:template> 
<xsl:param name="TagName"/> 
<xsl:template match="MessageStatus"> 
<xsl:element name="{$TagName}" xmlns="http://www.jdnasir.ac.ir/EMI/UserProxy/"> 
<xsl:for-each select="/MessageStatus/*"> 
<xsl:copy> 
<xsl:apply-templates select="@*|node()"/> 
</xsl:copy> 
</xsl:for-each> 
</xsl:element> 
</xsl:template> 
</xsl:stylesheet> 

這個XSLT的最棘手的部分是<xsl:element name="{$TagName}"部分。

我希望這可以幫助別人。