我在wso2 studio开发人员中使用xslt介体。我在wso2 carbon-> conf中添加以下代码作为本地实体(添加资源),并在我的xslt介体中将其用作“键”。=“” i =“”具有=“” list =“” of =“”对象=“” in =“” output =“” in =“” json =“”格式。=“”因为=“ =” even =“” i =“” need = “” list =“” of =“” one =“” object =“” so =“” i =“” use =“” this =“” mediator =“”代替=“” of =“” foreach =“”调解员。<=“” p =“”>
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet exclude-result-prefixes="xs" version="2.0" xmlns:fn="http://www.w3.org/2005/xpath-functions"
xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:a="http://schemas.datacontract.org/2004/07/Asa.Mbdp.Platform.Publish.Tmc.Head.Proxy"
xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:t="http://tempuri.org/">
<xsl:output encoding="UTF-8" indent="yes" media-type="application/json" method="text"/>
<xsl:strip-space elements="*"/>
<xsl:template match="/">
{
"Response":{
"LivePrices":[
<xsl:for-each select="s:Envelope/s:Body/t:LivePricesResponse/t:LivePricesResult/a:Close">
{
"Last":"<xsl:value-of select="a:Last"/>" ,
"Price":"<xsl:value-of select="a:Price"/>",
"Quantity":"<xsl:value-of select="a:Quantity"/>",
"Since":"<xsl:value-of select="a:Since"/>"
}
<xsl:if test="position()!=last()">,</xsl:if>
</xsl:for-each>
]
}
}
</xsl:template>
</xsl:stylesheet>
我的答复以我不想在其答复中添加的文本标签开头。如何删除此文本标签。
<text xmlns="http://ws.apache.org/commons/ns/payload">
{
"Response":{
"LivePrices":[
{
"Last":"1880" ,
"Price":"1851",
"Quantity":"0",
"Since":"2018-07-26T00:00:00"
}
]
}
}
</text>
我想要这个回复:
{
"Response":{
"LivePrices":[
{
"Last":"1880" ,
"Price":"1851",
"Quantity":"0",
"Since":"2018-07-26T00:00:00"
}
]
}
}
答案 0 :(得分:0)
使用XSLT之后,将以下代码放入您的序列中
<property name="messageType" scope="axis2" type="STRING" value="application/xml"/>
<payloadFactory media-type="json">
<format>$1</format>
<args>
<arg evaluator="xml" expression="$body//*" xmlns:ns="http://org.apache.synapse/xsd"/>
</args>
</payloadFactory>
<respond/>
这应该给您预期的输出