I am using xslt mediator in wso2 studio developer.I add below code as local entity (add resource) in wso2 carbon->conf and use it in my xslt mediator as "key". I have list of objects in output in json format. because even I need list of one object so I use this mediator instead of foreach mediator.
<?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>
my response start with text tag that I do not want to have it in my response. how can I remove this text tag.
<text xmlns="http://ws.apache.org/commons/ns/payload">
{
"Response":{
"LivePrices":[
{
"Last":"1880" ,
"Price":"1851",
"Quantity":"0",
"Since":"2018-07-26T00:00:00"
}
]
}
}
</text>
I want this response:
{
"Response":{
"LivePrices":[
{
"Last":"1880" ,
"Price":"1851",
"Quantity":"0",
"Since":"2018-07-26T00:00:00"
}
]
}
}
After using XSLT place the below code in your sequence
<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/>
This should give you the expected output
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.