【问题标题】:Xquery to find all words in italic <i>Xquery以斜体<i>查找所有单词
【发布时间】:2013-04-26 01:05:34
【问题描述】:

我正在尝试编写一个 XQuery,它将返回一个以斜体 () 表示的所有单词的列表,用于 xml,例如:

<p>There is abundant evidence of a widened and deepened interest in <i>modern</i>
 science. How could it be <i>otherwise</i> when we <i>think</i> of the magnitude and the
 eventfulness of recent advances?</p>

谢谢!

【问题讨论】:

    标签: xml xquery


    【解决方案1】:
    let $p := 
    <p>There is abundant evidence of a widened and deepened interest in 
    <i>modern</i> science. How could it be <i>otherwise</i> when we <i>think</i> of the
    magnitude and the eventfulness of recent advances?</p>
    return $p/i
    

    如果您将斜体嵌套在元素中,您可以使用$p//i 搜索所有后代。如果你想要一个字符串序列而不是 &lt;i&gt; 元素,你可以使用:

    for $i in $p/i
    return string($i)
    

    或者一些 XQuery 处理器将支持更简洁的$p/i/string()

    【讨论】:

    • mm.. 好吧,但是如果我必须从文档中加载?类似于: let $p:= doc("/documents/chapter_02.xml") //libro return $p/i
    • 如果处理器不支持 $p/i/string(),那么它就不是 XQuery 处理器。我会使用 $p//i/string() 因为标记几乎肯定允许嵌套再现标签。
    • @MichaelKay 好的,谢谢。也许我在想 XPath 1 vs 2?
    猜你喜欢
    • 2016-04-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-08-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-09-10
    相关资源
    最近更新 更多