I am using Java 1.8, Saxon-HE version 9.9.1-4 version and xslt3.0 to tranform the JSON to XML.
Input JSON
{
"analystId": "Test",
"jobId": "",
"profileData": {
"allAuthorCoverage": false,
"assetClasses": [
{
"code": "Test1"
}
]
}
}
XSLT3.0
<xsl:stylesheet version="3.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output indent="yes" />
<xsl:strip-space elements="*"/>
<xsl:param name="jsonText"/>
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template name="init">
<xsl:apply-templates select="json-to-xml($jsonText)"/>
</xsl:template>
<xsl:template match="*[@key]" >
<xsl:element name="{@key}">
<xsl:apply-templates/>
</xsl:element>
</xsl:template>
</xsl:stylesheet>
Output XML Generated
<?xml version="1.0" encoding="UTF-8"?>
<map xmlns="http://www.w3.org/2005/xpath-functions">
<analystId xmlns="">Test</analystId>
<jobId xmlns=""/>
<profileData xmlns="">
<allAuthorCoverage>false</allAuthorCoverage>
<assetClasses>
<map xmlns="http://www.w3.org/2005/xpath-functions">
<code xmlns="">Test1</code>
</map>
</assetClasses>
</profileData>
</map>
Output XML Expected
<?xml version="1.0" encoding="UTF-8"?>
<analystId>Test</analystId>
<jobId />
<profileData>
<allAuthorCoverage>false</allAuthorCoverage>
<assetClasses>
<code>Test1</code>
</assetClasses>
</profileData>
We can still see <map> element and xmlns attribute in the generated output and my requirement is to remove the same.
How can I remove the Map element from the generated output and xmlns attribute as well?
Also in case I expand my JSON structure with new attributes these map element and xmlns attribute should not be added back again.
xsl:template match="@* | node()"from the code that you have shown.