I am new to xslt,
I have a xml containing those elements
<cbl:ShippingAddress>
<cbl:AddressLine AddressLineNumber="1">
<cbl:Line>line1</cbl:Line>
</cbl:AddressLine>
<cbl:AddressLine AddressLineNumber="2">
<cbl:Line>line2</cbl:Line>
</cbl:AddressLine>
</cbl:ShippingAddress>
using this code
<map key="address">
<array key="lines">
<xsl:for-each select="/cbl:ShippingAddress/cbl:AddressLine/cbl:Line">
<map>
<string key="line">{.}</string>
</map>
</xsl:for-each>
</array>
</map>
I get the output
"lines": [
{
"line": "line1"
},
{
"line": "line2"
}
],
I need my output to be like this, but can’t figure out how
"lines": [
"line1",
"line2"
],
if i just change <array key="lines"> to <array>
I get the error message :
xml-to-json: Child elements of must have a key attribute
is there a simple way to achieve this? i’ve browse many example, couldn’t find it
2
Answers
Example
Online fiddle example.
Here’s another way you could look at this:
XML (corrected to well-formed!)
XSLT 3.0
Result
Demo