XQuery-输出带有分隔符的HTML元素系列
在XQuery3.1中,我正在构造一个HTML表。在一个XQuery-输出带有分隔符的HTML元素系列,xquery,exist-db,xquery-3.0,Xquery,Exist Db,Xquery 3.0,在XQuery3.1中,我正在构造一个HTML表。在一个元素中,我输出了一系列 因此,目前针对的这一简单的: <td> { for $b in collection($globalvar:URIdata)/tei:TEI/tei:text//tei:seg[@type="dep_event" and @corresp = $a/data(@corresp)
元素中,我输出了一系列
因此,目前针对的这一简单的:
<td>
{
for $b in collection($globalvar:URIdata)/tei:TEI/tei:text//tei:seg[@type="dep_event"
and @corresp = $a/data(@corresp)
and @xml:id != $a/data(@xml:id)]
order by $b/data(@xml:id)
return <a href="{concat($globalvar:URLdoc,$b/ancestor::tei:TEI/tei:text/@xml:id)}">{$b/data(@xml:id)}</a>
}
</td>
非常感谢您的建议。我不确定XQuery中是否有一个通用的习惯用法可以做到这一点,但我认为使用
for $b in collection($globalvar:URIdata)/tei:TEI/tei:text//tei:seg[@type="dep_event"
and @corresp = $a/data(@corresp)
and @xml:id != $a/data(@xml:id)]
order by $b/data(@xml:id)
count $p
let $a := <a href="{concat($globalvar:URLdoc,$b/ancestor::tei:TEI/tei:text/@xml:id)}">{$b/data(@xml:id)}</a>
return
if ($p > 1)
then (',', $a)
else $a
用于集合中的$b($globalvar:URIdata)/tei:tei/tei:text//tei:seg[@type=“dep_事件”
和@corresp=$a/数据(@corresp)
和@xml:id!=$a/data(@xml:id)]
按$b/数据订购(@xml:id)
数一数$p
租$a:=
返回
如果($p>1)
然后(“,”,$a)
要价$a
这是一种可能的方法,它与旧的XSLT方法非常相似,具有,
。接近这一点,你也可以试试
(
for $b in collection($globalvar:URIdata)/tei:TEI/tei:text//tei:seg[@type="dep_event"
and @corresp = $a/data(@corresp)
and @xml:id != $a/data(@xml:id)]
order by $b/data(@xml:id)
return <a href="{concat($globalvar:URLdoc,$b/ancestor::tei:TEI/tei:text/@xml:id)}">{$b/data(@xml:id)}</a>
) ! (if (position() > 1) then (',', .) else .)
(
对于集合中的$b($globalvar:URIdata)/tei:tei/tei:text//tei:seg[@type=“dep_event”
和@corresp=$a/数据(@corresp)
和@xml:id!=$a/data(@xml:id)]
按$b/数据订购(@xml:id)
返回
) ! (如果(position()>1),则(',',.)else。)
这也可以写成
(
for $b in collection($globalvar:URIdata)/tei:TEI/tei:text//tei:seg[@type="dep_event"
and @corresp = $a/data(@corresp)
and @xml:id != $a/data(@xml:id)]
order by $b/data(@xml:id)
return <a href="{concat($globalvar:URLdoc,$b/ancestor::tei:TEI/tei:text/@xml:id)}">{$b/data(@xml:id)}</a>
) ! (if (position() > 1) then ',' else (), .)
(
对于集合中的$b($globalvar:URIdata)/tei:tei/tei:text//tei:seg[@type=“dep_event”
和@corresp=$a/数据(@corresp)
和@xml:id!=$a/data(@xml:id)]
按$b/数据订购(@xml:id)
返回
) ! (如果(position()>1),则“,”else(),”
有点接近你的第二次尝试。我刚刚在我的问题中编辑了一些类似的东西,使用xquery的在$y中的$x位置-count
是一个分配变量的函数。奇怪的是,orderby
现在被XQuery作为基数问题拒绝了。那么这将是另一个问题,您还没有显示在新尝试中将订单放在哪里。我的两个建议都没有改变您的原始代码,只是将它们合并到更大的表达式中。我只是尝试了您的第二个建议,效果很好。这是一个迷人的解决方案,我只了解一半。什么是代码>这样做允许(如果(position()>1)然后(“,”,)else。)
操作?
是XPath 3中分别引入的所谓的“map”操作符XQuery 3,用于将左侧序列的每个项映射到右侧的表达式。因此,在简单的语言中,查询结果
是一个序列(位于!
的左侧),并将XSLT位置()映射到该结果(位于右侧)
以确定是否应在此基础上执行某些操作?
for $b in collection($globalvar:URIdata)/tei:TEI/tei:text//tei:seg[@type="dep_event"
and @corresp = $a/data(@corresp)
and @xml:id != $a/data(@xml:id)]
order by $b/data(@xml:id)
count $p
let $a := <a href="{concat($globalvar:URLdoc,$b/ancestor::tei:TEI/tei:text/@xml:id)}">{$b/data(@xml:id)}</a>
return
if ($p > 1)
then (',', $a)
else $a
(
for $b in collection($globalvar:URIdata)/tei:TEI/tei:text//tei:seg[@type="dep_event"
and @corresp = $a/data(@corresp)
and @xml:id != $a/data(@xml:id)]
order by $b/data(@xml:id)
return <a href="{concat($globalvar:URLdoc,$b/ancestor::tei:TEI/tei:text/@xml:id)}">{$b/data(@xml:id)}</a>
) ! (if (position() > 1) then (',', .) else .)
(
for $b in collection($globalvar:URIdata)/tei:TEI/tei:text//tei:seg[@type="dep_event"
and @corresp = $a/data(@corresp)
and @xml:id != $a/data(@xml:id)]
order by $b/data(@xml:id)
return <a href="{concat($globalvar:URLdoc,$b/ancestor::tei:TEI/tei:text/@xml:id)}">{$b/data(@xml:id)}</a>
) ! (if (position() > 1) then ',' else (), .)