I am trying to fetch data from array list, I'm using xslt 3.0 (saxon-HE v11.4 library) to convert json to xml in Java. If data in array list is empty string then space should appended in the required output.
Below are required details: sample json input:
{
"employee":{
"id":["1","2",""]
}
}
required output:
<employee>
<id>
<id indexarray="0">1</id>
<id indexarray="1">2</id>
<id indexarray="2"> </id>
</id>
<name>
<name indexarray="0">a</name>
<name indexarray="1"> </name>
<name indexarray="2"> </name>
</name>
</employee>
tried below code
<id>
<xsl:for-each select="$employee?id?*">
<xsl:choose>
<xsl:when test="$employee?id?*!=''">
<id indexarray="{position()-1}">{.}</id>
<xsl:otherwise>
<id indexarray="{position()-1}"> </id>
</xsl:otherwise>
</xsl:choose>
</xsl:for-each>
</id>
getting output as below:
<id>
<id indexarray="0">1</id>
<id indexarray="1">2</id>
<id indexarray="2"/>
</id>
Any help is appreciated.