我有以下XML文件:XQuery的標記化的字符串與單個和多個值
<layout>
<layout-structure>
<layout-root id="layout-root">
<layout-chunk id="header-text">
<layout-leaf xref="lay-1.01"/>
<layout-leaf xref="lay-1.02"/>
</layout-chunk>
<layout-leaf xref="lay-1.03"/>
</layout-root>
<layout-root id="layout-root-two">
<layout-chunk id="header-text-two">
<layout-leaf xref="lay-1.04"/>
<layout-leaf xref="lay-1.05"/>
<layout-leaf xref="lay-1.06"/>
</layout-chunk>
<layout-leaf xref="lay-1.07"/>
</layout-root>
</layout-structure>
<realization>
<text xref="lay-1.01 lay-1.04"/>
<text xref="lay-1.02 lay-1.05"/>
<graphics xref="lay-1.03 lay-1.06" type="1"/>
<graphics xref="lay-1.07" type="2"/>
</realization>
</layout>
我要提取的值的圖形元件的外部參照屬性,以便限制輸出在中爲子句的功能如下所示。
declare function local:gfx($root, $graphics) {
let $graphic-xrefs := tokenize($graphics/@xref, " ")
for $layout-leafs in $root//layout-leaf[@xref = $graphic-xrefs]
return concat('"', $layout-leafs/@xref, '" ', $dotgraphics, ';', $newline)
};
然而,這會導致錯誤,因爲下圖形一些外部參照的屬性元件包含一個單一的值,如在<graphics xref="lay-1.07"/>
的情況。
是否有可能使用標記化來獲取圖形/外部參照值,或者我應該使用不同的方法?
感謝您的輸入@dirkk!奇怪的是,我在Editix中得到以下錯誤信息:'不允許多個項目的序列作爲tokenize()的第一個參數(「lay-1.03」,「lay-1.06」)' – ritzdiamond
發生了這種事情當你真的執行我的代碼(或只是爲了你的原始代碼)?因爲對於我的代碼,我會感到很驚訝。該錯誤消息還表明,確實錯誤在於如何調用函數'local:gfx':聽起來像$ graphics/@ xref不僅僅是一個單獨的元素,而是一系列多個節點。但是作爲tokenize的輸入,你必須傳遞一個xs:string並且沒有序列。我強烈建議檢查你如何調用函數和你傳遞的變量。如果您想要進一步提供建議,請張貼您稱呼該功能的方式。 – dirkk