[英]xquery efficient predicates versus for…where
我有一系列看起來像這樣的 xml 節點:
let $x :=
<works>
<work xml:id="W1">
<author corresp="AU08"/>
<group corresp="GR03"/>
</work>
<work xml:id="W2">
<author corresp="AU09"/>
<group corresp="GR10"/>
</work>
<work xml:id="W3">
<author corresp="AU08"/>
<group corresp="GR05"/>
</work>
....
</works>
我有一個搜索表單,它可能會或可能不會針對work/@xml:id
、 work/author/@corresp
和work/affiliation/$corresp
提供序列參數,例如:
let $xmlids := ("W1")
let $authors := ()
let $groups := ("GR05","GR08")
或者
let $xmlids := ()
let $authors := ("AU01","AU08")
let $groups := ("GR05")
我正在嘗試在 Xquery 3.1 (eXist 4.7) 中創建一個有效的查詢,以考慮參數的不同排列,同時輸出work/
。 這導致我構建了一系列丑陋的嵌套if
語句,它們試圖支持謂詞而不是for...where
如下所示:
if (count($xmlids) gt 0 and count($authors) gt 0 and count($groups) gt 0)
then
$x/id($xmlids)/author[@corresp=$authors]/parent::work/group[@corresp=$groups]/parent::work
else if (count($xmlids) gt 0 and count($authors) gt 0 and count($groups) eq 0)
then
$x/id($xmlids)/author[@corresp=$authors]/parent::work
else if ...
有沒有更有效的方法來構建一個 Xquery 來考慮變量存在/不存在的參數?
提前謝謝了。
我認為對於謂詞,您只需要@corresp=$authors or not(exists($authors))
和@corresp=$groups or not(exists($groups))
。
對於id
呼叫,我認為您需要
let $work-items := if ($x/id($xmlids)) then $x/id($xmlids) else $x/work
return $work-items[author[@corresp=$authors or not(exists($authors))] and group[@corresp=$groups or not(exists($groups))]]
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.