Transforming JSON Object without root name Transforming JSON Object without root name json json

Transforming JSON Object without root name


In a no-root name array json, you can use below xslt for <id> tag. Key point is <jsonArray><jsonElement></jsonElement></jsonArray> appoach. But you need to be careful about <jsonElement>, it should be in a <xsl:for-each select="//jsonArray/jsonElement"> block. For not exposuring the for each syndrome, you should not write the root element for fields in it. For example <xsl:if test="id">.

<xsl:stylesheet version="2.0"        xmlns:xsl="http://www.w3.org/1999/XSL/Transform"        xmlns:xs="http://www.w3.org/2001/XMLSchema"        xmlns:fn="http://www.w3.org/2005/xpath-functions"        xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"        xmlns:ns1="http://www.qas.com/OnDemand-2011-03"        xmlns:json="http://json.org">    <xsl:output method="xml" omit-xml-declaration="yes" encoding="UTF-8" indent="yes" />    <xsl:template match="/">        <jsonArray>            <xsl:for-each select="//jsonArray/jsonElement">                <jsonElement>                       <xsl:if test="id">                        <id><xsl:value-of select="id" /> </id>                    </xsl:if>                </jsonElement>            </xsl:for-each>        </jsonArray>    </xsl:template></xsl:stylesheet>