两个单例标记之间的XQuery内容

时间:2023-02-01 16:13:49

do you know to do XQuery query for selection of content between two singleton tags, e.g.

你知道吗XQuery查询选择两个单例标签之间的内容,例如

<pb n="1"/>
   this is <foo>page</foo> number one
<pb n="2"/>
   this is <bar>page</bar> number two
<pb n="3"/>
   this is <x>page</x> number three

and I want for example content of second page, so between <pb n="2"/> and next <pb/>. Output should be then:

我希望例如第二页的内容,所以在 和下一个 之间。输出应该是:

   this is <bar>page</bar> number two

3 个解决方案

#1


3  

You can do this using following-sibling together with the << operator, like this:

您可以使用follow-sibling和< <运算符一起执行此操作,如下所示:< p>

let $xml := <xml>
<pb n="1"/> 
   this is <foo>page</foo> number one 
<pb n="2"/> 
   this is <bar>page</bar> number two 
<pb n="3"/> 
   this is <x>page</x> number three 
</xml>
return
  $xml/pb[2]/following-sibling::node()[. << $xml/pb[3]]

HTH!

HTH!

#2


1  

See David Sewell's milestone-chunk() function on the TEI wiki. Note that this article also points to an eXist-db extension function, util:get-fragment-between().

在TEI wiki上查看David Sewell的milestone-chunk()函数。请注意,本文还指出了一个eXist-db扩展函数,util:get-fragment-between()。

#3


0  

Just this query, which happens to be a pure XPath 2.0 expression:

只是这个查询,恰好是纯XPath 2.0表达式:

/*/node()[not(self::pb) and preceding-sibling::pb[1]/@n eq '2']

When executed on this XML document (the provided XML fragment wrapped into a single top element):

在此XML文档上执行时(提供的XML片段包装在单个顶部元素中):

<t>
    <pb n="1"/>
       this is <foo>page</foo> number one
    <pb n="2"/>
       this is <bar>page</bar> number two
    <pb n="3"/>
       this is <x>page</x> number three
</t>

the wanted, correct result is produced:

产生了想要的正确结果:

   this is <bar>page</bar> number two

#1


3  

You can do this using following-sibling together with the << operator, like this:

您可以使用follow-sibling和< <运算符一起执行此操作,如下所示:< p>

let $xml := <xml>
<pb n="1"/> 
   this is <foo>page</foo> number one 
<pb n="2"/> 
   this is <bar>page</bar> number two 
<pb n="3"/> 
   this is <x>page</x> number three 
</xml>
return
  $xml/pb[2]/following-sibling::node()[. << $xml/pb[3]]

HTH!

HTH!

#2


1  

See David Sewell's milestone-chunk() function on the TEI wiki. Note that this article also points to an eXist-db extension function, util:get-fragment-between().

在TEI wiki上查看David Sewell的milestone-chunk()函数。请注意,本文还指出了一个eXist-db扩展函数,util:get-fragment-between()。

#3


0  

Just this query, which happens to be a pure XPath 2.0 expression:

只是这个查询,恰好是纯XPath 2.0表达式:

/*/node()[not(self::pb) and preceding-sibling::pb[1]/@n eq '2']

When executed on this XML document (the provided XML fragment wrapped into a single top element):

在此XML文档上执行时(提供的XML片段包装在单个顶部元素中):

<t>
    <pb n="1"/>
       this is <foo>page</foo> number one
    <pb n="2"/>
       this is <bar>page</bar> number two
    <pb n="3"/>
       this is <x>page</x> number three
</t>

the wanted, correct result is produced:

产生了想要的正确结果:

   this is <bar>page</bar> number two