Problem: I have a given JSON output and need to transform this into a xml with a given format to use it for another input.
The JSON-document: report.json
{
"Diagnostic Cycle" : "2019-02-13T08:19:44ZZ",
"01 Tester" : {
"01 Name" : "IPTester",
"02 Operating System" : "Linux",
"03 Node Name" : "tester15",
"04 Release Level" : "5.4.7",
"06 Machine" : "i686",
"07 Domain Name" : "(none)"
}
,
"02 Device Name" :
{
"SampleECU":
{
"01 Diagnostic" : "OK",
"02 CAN Id" : "(none)",
"02 DoIP Id" : "00FFh 124Ah 85B1h",
"03 VIN original" : "BZ7282399843",
"04 VIN current" : "ERROR 11",
"05 HW Part No" : "887895414",
"06 DTC Status 01" : 1,
"10 Hardware Year" : 2020,
"11 Hardware Week" : 08,
"12 Hardware Patch" : 0,
"20 Software Year" : 2020,
"21 Software Week" : 08,
"22 Software Patch" : 0,
"30 Bootware" : "ERROR 11"
}
}
How the XML-output should look:
<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet type="text/xsl" href="./My_Stylesheet.xsl"?>
<VehicleReport xsi:schemaLocation="http://www.w3.org/xsd/vdx30 VDX.3.2.1.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" VDXVersion="3.2.1" xmlns="http://www.w3.org/xsd/vdx30">
<ServiceTool>
<Name>IPTester</Name>
<Version>5.4.7</Version>
<UserID>tester15</UserID>
<ExecutionTime>2019-02-13T08:19:44ZZ</ExecutionTime>
</ServiceTool>
<VehicleInformation>
<IdentificationNumberValue>BZ7282399843</IdentificationNumberValue>
</VehicleInformation>
<ComponentList>
<Component>
<ECUShortName>SampleECU</ECUShortName>
<DiagnosticInfo>
<DiagnosticInfoValue>1</DiagnosticInfoValue>
</DiagnosticInfo>
<SWHWInformation>
<Software>
<Version>
<VersionValue>20/08/00</VersionValue>
</Version>
</Software>
<Hardware>
<PartNumber>
<PartNumberValue>887895414</PartNumberValue>
</PartNumber>
<Version>
<VersionValue>20/08/00</VersionValue>
</Version>
</Hardware>
</SWHWInformation>
</Component>
</ComponentList>
</VehicleReport>
I heard I should use the Saxon XSLT Processor for a XSLT-transformation, but I dont know how (no XSLT experience).
The two ways I can think of:
- First use json-to-xml() then transform the xml with XSLT
- Populate the XML directly with JSON-values (preferred because simple)
But I dont know how to do both - a tutorial for XSLT would be appreciated.