On 12.12.2017 13:30, Hondros, Constantine (ELS-AMS) wrote:
I was already kicking myself for rushing and not providing a SCE! Please see the code below, and thanks.
declare option output:method 'json';
declare variable $authors := <authors>
<author>
<given-name>Robert A</given-name>
<surname>Sanders</surname>
</author>
<author>
<given-name>Emily</given-name>
<surname>Chapel</surname>
</author>
</authors>;
map {
"authors": [
(for $b in $authors/author return
map{"fn":$b/*:given-name/text(), "ln":$b/*:surname/text()})
]
}
I think to get the map structure from your earlier sample you want
declare option output:method 'json';
declare variable $authors := <authors>
<author>
<given-name>Robert A</given-name>
<surname>Sanders</surname>
</author>
<author>
<given-name>Emily</given-name>
<surname>Chapel</surname>
</author>
</authors>;
map {
"authors": array{$authors/author!map{"fn" : data(given-name), "ln" : data(surname)}}
}
Result is
{ "authors": [ { "ln": "Sanders", "fn": "Robert A" }, { "ln": "Chapel", "fn": "Emily" } ] }