WSO2富集阵列
我正在使用WSO2 ESB(4.8.1),我需要转换此负载:WSO2富集阵列,wso2,wso2esb,Wso2,Wso2esb,我正在使用WSO2 ESB(4.8.1),我需要转换此负载: [ { "id":"1", "budget":"a" }, { "id":"2", "bidget:"b" } ] 在本例中,使用enrich mediator(如果可能的话): 有什么建议吗 提前感谢我想当你不知道数组的长度时,你不能用enrich或payloadFactory转换它。我在WSO2 ESB文档中发现了相同的问题。此JS函数用于转换对象数组 functi
[
{
"id":"1",
"budget":"a"
},
{
"id":"2",
"bidget:"b"
}
]
在本例中,使用enrich mediator(如果可能的话):
有什么建议吗
提前感谢我想当你不知道数组的长度时,你不能用enrich或payloadFactory转换它。我在WSO2 ESB文档中发现了相同的问题。此JS函数用于转换对象数组
function transform(mc) {
payload = mc.getPayloadJSON();
results = payload.results;
var response = new Array();
for (i = 0; i < results.length; ++i) {
location_object = results[i];
l = new Object();
l.name = location_object.name;
l.tags = location_object.types;
l.id = "ID:" + (location_object.id);
response[i] = l;
}
mc.setPayloadJSON(response);
}
函数变换(mc){
payload=mc.getPayloadJSON();
结果=有效载荷。结果;
var响应=新数组();
对于(i=0;i有关更多信息,请参阅中的scipte mediator。查看此示例: 输入文件:
<?xml version="1.0" encoding="UTF-8" ?>
<employees>
<root>
<id>1</id>
<budget>a</budget>
</root>
<root>
<id>2</id>
<budget>b</budget>
</root>
<root>
<id>3</id>
<budget>c</budget>
</root>
</employees>
1.
A.
2.
B
3.
C
我的xslt:
<?xml version='1.0' ?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<employees>
<xsl:for-each select="employees/root">
<root>
<id>
<xsl:value-of select="id"/>
</id>
<budget>
<xsl:value-of select="budget"/>
</budget>
<result>
<xsl:value-of select="concat(id,'-',budget)"/>
</result>
</root>
</xsl:for-each>
</employees>
</xsl:template>
</xsl:stylesheet>
输出文件:
<?xml version="1.0" encoding="UTF-8" ?>
<employees>
<root>
<id>1</id>
<budget>a</budget>
<result>1-a</result>
</root>
<root>
<id>2</id>
<budget>b</budget>
<result>2-b</result>
</root>
<root>
<id>3</id>
<budget>c</budget>
<result>3-c</result>
</root>
</employees>
1.
A.
1-a
2.
B
2-b
3.
C
3-c
因此,您可以在WSO2 ESB()和此配置或类似配置中使用xslt中介,并使用您的定义。
注意。您可以使用XML消息并创建XSL转换
<?xml version="1.0" encoding="UTF-8" ?>
<employees>
<root>
<id>1</id>
<budget>a</budget>
<result>1-a</result>
</root>
<root>
<id>2</id>
<budget>b</budget>
<result>2-b</result>
</root>
<root>
<id>3</id>
<budget>c</budget>
<result>3-c</result>
</root>
</employees>