【发布时间】:2015-02-12 08:25:25
【问题描述】:
我正在将一个 XQuery 文件应用于两个 XML 文件:
-file1/sn-p1-
<entry xml:id="SCHOM-2">
<form type="hyperlemma" xml:lang="cu">
<orth>абиѥ</orth>
</form>
<form type="lemma" xml:lang="cu">
<orth>абиѥ</orth>
<cit type="counterpart" xml:lang="grc">
<form type="hyperlemma" xml:lang="grc">
<orth>παραχρῆμα</orth>
</form>
<form type="lemma" xml:lang="grc">
<orth>παραχρῆμα</orth>
</form>
</cit>
</form>
</entry>
和 -file2/sn-p2-
<entry xml:id="arg-3150">
<form type="hyperlemma" xml:lang="grc">
<orth>ἐξαυτῆς</orth>
</form>
<form type="lemma" xml:lang="grc">
<orth>ἐξαυτῆς</orth>
<cit type="translation" xml:lang="cu">
<form type="hyperlemma" xml:lang="cu">
<orth>абиѥ</orth>
</form>
<form type="lemma" xml:lang="cu">
<orth>абие</orth>
</form>
</cit>
</form>
</entry>
两个 sn-ps 具有相同的结构。如果我在任何 <form type="hyperlemma"> 中查找“абиѥ”,则 sn-p1 的路径是 $file//entry/form[@type='hyperlemma']/orth (path1),而 sn-p2 是 $file//entry/form/cit/form[@type='hyperlemma']/orth (path2)。
在 XQuery 文件中,我有以下 FLWOR 表达式:
xquery version "3.0";
...
for $file in collection($collection_path),
$path_to_hyperlemma in $file//(entry | cit)/form[@type='hyperlemma']/orth [ft:query(., $searchphrase)]
let $entry_number := $path_to_hyperlemma/../../@xml:id
return
....
$entry_number 应该存储<entry xml:id=""> 的属性值。但是我这样做的方式(使用/../../)当然只返回$file//entry/form[@type='hyperlemma']/orth 的属性值。
是否可以将属性值存储在$entry_number中,不管是path1还是path2?
另一个问题:我知道使用// 在性能方面并不理想。但是如果我用绝对路径替换//,我似乎无法引用不同级别的节点集。在这种情况下是否可以设置绝对路径?
【问题讨论】:
-
这里不是很清楚问题出在哪里,你能展示一个你正在查询的 XML 的小样本吗?
-
@IanRoberts:我添加了两个 XML sn-ps 并重新表述了我的问题。我希望它现在变得更加清晰......