Vote count:
0
My document is in XML and I need to construct a JSON format based on this document. First I created a query returning the right XML structure but when I convert this query to return JSON, I have a For Return problem.
Error: [1.0-ml] XDMP-UNDVAR: (err:XPST0008) Undefined variable $cat
Original query:
let $tree :=
<tree>{for $cat in distinct-values($doc//ns:category/@name)
return <cat name="{$cat}">
{ for $var in $doc//ns:category[@name = $cat]//ns:variable/@name
return <var name="{$var}">
}
</var>
}
</cat>
}
</tree>
return $tree
Data:
<category name="Catname">
<variable name="Varname">
<segment name="Seg1">9</segment>
<segment name="Seg2">33</segment>
<segment name="Seg3">32</segment>
<segment name="Seg4">22</segment>
</variable>
</category>
New Query:
let $tree :=
json:array(
<json:array xmlns:json="http://ift.tt/1wxrEES"
xmlns:xs="http://ift.tt/tphNwY"
xmlns:xsi="http://ift.tt/ra1lAU">
<json:value xsi:type="xs:string">
{for $cat in distinct-values($doc//ns:category/@name) return $cat}
</json:value>
<json:array>
{for $var in $doc//ns:category[@name = $cat]//ns:variable/@name return $var}
</json:array>
</json:array>
)
return $tree
asked 24 secs ago
Aucun commentaire:
Enregistrer un commentaire