I want to convert existing json file to xml file and some values:
json file:
{
"Code": "111",
"UnitCode": "XYZ",
"valueCond": {
"ir": "#001",
"nk": "portal"
},
"property": "AFB139"
}
desire xml file:
<map>
<Code>111</Code>
<UnitCode>XYZ</UnitCode>
<valueCond>
<ir>#001_1234</ir>
<nk>portal:zeo</nk>
<valueCond>
<property>AFB139<property>
</map>
I use function json-to-xml, but in the result I get only values without name of elements…How in the result file I can have xml structure with element and values
<xsl:template name="xsl:initial-template">
<xsl:variable name="json-as-xml" select="json-to-xml(unparsed-text($input-json)"/>
<xsl:apply-templates select="$json-as-xml"/>
</xsl:template>
2
Answers
Well, you need to transform the result of
json-to-xml
further e.g.Result is e.g.
Add further templates like e.g.
to change those values and get e.g.
Online fiddle example (JSON is inlined there as string param value).
I don’t think I would use json-to-xml for this. I would do it "by hand":
(Adding any data changes that you need to make at the same time – these aren’t clear in your requirements.)