问问题
179 次
2 回答
1
当您使用 XQuery 3.0 时,一个快速的解决方案是按条目 ID 进行分组,无论如何您都在解决这个问题:
(: snip :)
for $hyperlemma in $hyperlemmas
let $entry_id := $hyperlemma/ancestor::entry/@xml:id
group by $entry_id
let $lemma := $hyperlemma/ancestor::entry/lemma/orth
let $variant := $hyperlemma/ancestor::entry/variant/orth
return
(: snip :)
一个更优雅的解决方案(但几乎导致完全重写查询)是循环遍历条目元素,并为每个找到第一个匹配项并打印它。
于 2015-05-21T09:38:47.223 回答
1
entry
当可以在不同的位置找到给定的搜索词时,我终于弄清楚了如何在标签内打印某些元素。这是重写的 XQuery 代码(目前)对我有用并给出了预期的结果:
xquery version "3.0";
declare namespace output = "http://www.w3.org/2010/xslt-xquery-serialization";
declare option output:method "xml";
declare variable $searchphrase := "ἄγγελος";
<html>
<head>
<meta HTTP-EQUIV="Content-Type" content="text/html; charset=UTF-8"/>
</head>
<body>
<h1>Output of searchterm</h1>
<p>You are looking for "<font color="red"><strong>{$searchphrase}</strong></font>"</p>
{
let $hyperlemmas := doc("sample_entry.xml")/(descendant::entry | descendant::cit)/hyperlemma/orth [contains(., $searchphrase)]
let $ids := $hyperlemmas/ancestor::entry/@xml:id
return
<p>{$searchphrase} was found {count($hyperlemmas)} times. IDs: {data($ids)} </p>
}
{
let $entry_base := doc("sample_entry.xml")/text
for $entry in $entry_base/entry
let $id := $entry/@xml:id
let $variant := $entry/variant/orth
let $found_pos1 := $entry/hyperlemma/orth
let $found_pos2 := $entry/descendant::cit/hyperlemma/orth
where $found_pos1 = $searchphrase or $found_pos2 = $searchphrase
return
<div>ID {data($id)}:<br/>Lemma: {$entry/lemma/orth}<br/>
{
for $item in $variant
return
<div>Variant: {$item}
{
for $cit in $item/../cit/lemma
where exists($cit)
return
<i>-> {$cit}</i>
}
</div>
}
</div>
}
</body>
</html>
于 2015-05-22T14:47:58.753 回答