I have been checking related entries in SO and so far no luck, as my use case seems to have some commonalities but also differences with provided solutions (like: Converting json array to xml using XSLT or Convert JSON to XML using XSLT 3.0 functions).
so hopefully somebody can help me here please.
I call the transformation like this:
java -jar SaxonHE/saxon-he-11.4.jar -s:not_used.xml -xsl:rework_map.xsl -o:report-map.xml p1="list.json"
INPUT: list.json - file produced externally and not embedded in xml, containing array of entries, like:
[
{
"tc_id": "A_S_0001",
"file_name": "\\scripts\\A_S_0001.cs",
"version": "19",
"is_automated": true
},
{
"tc_id": "A_S_0002",
"file_name": "\\scripts\\A_S_0002.cs",
"version": "25",
"is_automated": false
}
]
EXPECTED OUTPUT: something like this:
<list>
<test_case>
<tc_id>A_S_0001</tc_id>
<file_name>\\scripts\\A_S_0001.cs</file_name>
<version>19</version>
<is_automated>true</is_automated>
</test_case>
<test_case>
<tc_id>A_S_0002</tc_id>
<file_name>\\scripts\\A_S_0002.cs</file_name>
<version>25</version>
<is_automated>false</is_automated>
</test_case>
</list>
my template rework_map.xsl (not working)
<xsl:stylesheet 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:math="http://www.w3.org/2005/xpath-functions/math"
xmlns:map="http://www.w3.org/2005/xpath-functions/map"
xmlns:array="http://www.w3.org/2005/xpath-functions/array"
exclude-result-prefixes="xs math map array fn"
version="3.0">
<!-- OUTPUT -->
<xsl:output method="xml" indent="yes"/>
<!-- PARAMETERS -->
<xsl:param name="p1"></xsl:param> <!-- list.json -->
<!-- VARIABLES -->
<xsl:variable name="json-array" select="json-doc($p1)"/>
<xsl:template match="/">
<!-- <xsl:call-template name="common.INFO"/> -->
<list>
<xsl:apply-templates select="$json-array/*"/>
</list>
</xsl:template>
<xsl:template match="fn:map">
<test_case>
<xsl:apply-templates/>
</test_case>
</xsl:template>
<xsl:template match="fn:map/fn:*">
<xsl:element name="{@key}">
<xsl:value-of select="."/>
</xsl:element>
</xsl:template>
</xsl:stylesheet>