Example XSLT to Convert BookQuery XML Response to JSON Response
Use the following XSLT to convert XML message format to JSON message format:
<xsl:stylesheet version="1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:ns0="http://www.example.com/xsd/books" xmlns:fn="http://www.tibco.com/asg/functions/json" xmlns:json="http://www.tibco.com/asg/content-types/json" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" exclude-result-prefixes="xsl fn json ns0 SOAP-ENV"> <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes" omit-xml-declaration="yes"/> <xsl:variable name="cnResponseHref"> <xsl:value-of select="/transformation/cnResponse/@href"/> </xsl:variable> <xsl:variable name="cnResponse"> <xsl:copy-of select="document($cnResponseHref)/*"/> </xsl:variable> <xsl:variable name="JsonXmlResponse"> <json:json_xml> <json:dict> <json:dict key="BookStore"> <json:list key="Book"> <xsl:for-each select="$cnResponse/SOAP-ENV:Envelope/SOAP-ENV:Body/ns0:BookStore/ns0:Book"> <json:dict key="Book"> <json:text key="Title"><xsl:value-of select="ns0:Title"/></json:text> <json:text key="ISBN"><xsl:value-of select="ns0:ISBN"/></json:text> <json:text key="Author"><xsl:value-of select="ns0:Author"/></json:text> <json:text key="Publisher"><xsl:value-of select="ns0:Publisher"/></json:text> </json:dict> </xsl:for-each> </json:list> </json:dict> </json:dict> </json:json_xml> </xsl:variable> <xsl:template match="/"> <xsl:value-of select="fn:render($JsonXmlResponse//json:json_xml/json:dict)"/> </xsl:template> </xsl:stylesheet>
Copyright © Cloud Software Group, Inc. All rights reserved.