I'm converting xml to json using xslt. The problem I'm having is: if a specific xml element dosn't have siblings it is not returned as an array.
<xsl:if test="count(preceding-sibling::*[name() = name(current())]) = 0">
<xsl:text>"</xsl:text><xsl:value-of select="name()" /><xsl:text>":</xsl:text>
<xsl:if test="count(following-sibling::*[name() = name(current())]) > 0">
<xsl:text>[</xsl:text>
</xsl:if>
</xsl:if>
What I would like is if siblings of the parent have have the same element(s) as an array then this element must also be an array.
so what I would like is:
<element>
<child_element>
<grandchild_element>
only one
</grandchild_element>
</child_element>
<child_element>
<grandchild_element>
one
</grandchild_element>
<grandchild_element>
two
</grandchild_element>
</child_element>
I would like the following output
{
"element": {
"child-element": [
{
"grandchild_element": "only one"
}
],
"child-element": [
{
"grandchild_element": "one" ,
"grandchild_element": "two"
}
]
}
}
thanks