我需要從地圖創建specificly格式的文檔Marklogic如何從地圖上創建的文檔
我有以下代碼:
declare function local:buid-map-doc(
$wijk as xs:string,
$wm as map:map) as element()
{
let $a := for $k in map:keys($wm)
let $v := map:get($wm,$k)
return element x {$v}
return <y>{$a}</y>
};
let $wijk := "101101"
let $wm := map:map()
let $p := map:put($wm, "cat1:::k1",45683)
let $p := map:put($wm, "cat1:::k2",123)
let $p := map:put($wm, "cat2:::k2",123)
return local:buid-map-doc($wijk,$wm)
給出:
<y>
<x>123</x>
<x>123</x>
<x>45683</x>
</y>
但我想要的地圖:按鍵我的元素名稱... 如果我這樣做:
declare function local:buid-map-doc(
$wijk as xs:string,
$wm as map:map) as element()
{
let $a := for $k in map:keys($wm)
let $v := map:get($wm,$k)
return element {$k} {$v}
return <y>{$a}</y>
};
let $wijk := "101101"
let $wm := map:map()
let $p := map:put($wm, "cat1:::k1",45683)
let $p := map:put($wm, "cat1:::k2",123)
let $p := map:put($wm, "cat2:::k2",123)
return local:buid-map-doc($wijk,$wm)
然後我得到錯誤等:
[1.0毫升] XDMP-QNAMELEXFORM:讓$ S:= FN:QName的( 「http://www.example.com/example」, 「K」) - 無效詞法爲的QName
形式增加:
理想我想更深層次的嵌套得到輸出這樣的,可能還有:
<results>
<cat1>
<k1>45683</k1>
<k2>123</k2>
</cat1>
<cat2>
<k2>123</k2>
</cat2>
</results>
實際上在真正的問題,我們有3層的關鍵和最終的解決方案是使用嵌套地圖來獲得我們需要的結構... thx爲您的幫助 –
@HugoKoopmans:我將分享與代碼最相關的部分上市.. – grtjn