如何使用FLOWR和XQuery创建新的列表项? [英] How to create a new list item with FLOWR and XQuery?

查看:162
本文介绍了如何使用FLOWR和XQuery创建新的列表项?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找从XML文件中选择非数字数据,以将其分解为数据库列或至少一个类似xmltable的结构.此FLWOR给出了一些有用的结果:

I'm looking to select non-numerical data from an XML file towards shredding it into database columns, or at least an xmltable-like structure. This FLWOR gives a somewhat useful result:

xquery version "3.0";
declare namespace office="urn:oasis:names:tc:opendocument:xmlns:text:1.0";

<ul>
{
for $foo  in db:open("foo")
return <li>{$foo//text()[not(matches(., '[0-9]'))]}</li>

}
</ul>

但是,它将所有结果输出到单个li标签中,例如:

However, it outputs all results into a single li tag, like:

  • a b c d

首选输出将采用以下形式:

Preferred output would be of the form:

  • a
  • b

数据很可能在某种程度上有问题,因为FLOWR略有不同:

xquery version "3.0";
declare namespace office="urn:oasis:names:tc:opendocument:xmlns:text:1.0";

for $foo in db:open("foo")
return $foo//text()[not(matches(., '[0-9]'))]

肯定在新行上输出每个非数字字符串.如何将其输出到列表?

certainly outputs each non-numerical string on a new line. How can I output this into a list?

数据摘录:

 <table:table-column table:style-name="co1" table:default-cell-style-name="ce17"/>
  <table:table-row table:style-name="ro1">
    <table:table-cell table:style-name="ce15" office:value-type="string" calcext:value-type="string">
      <text:p>John Smith</text:p>
    </table:table-cell>
  </table:table-row>
  <table:table-row table:style-name="ro2">
    <table:table-cell table:style-name="ce16" office:value-type="string" calcext:value-type="string">
      <text:p>(123) 456-7890</text:p>
    </table:table-cell>
  </table:table-row>
  <table:table-row table:style-name="ro2">
    <table:table-cell office:value-type="string" calcext:value-type="string">
      <text:p>123 Main Street</text:p>
    </table:table-cell>
  </table:table-row>
  <table:table-row table:style-name="ro2">
    <table:table-cell office:value-type="string" calcext:value-type="string">
      <text:p>Anywhere, ZZ 12345-6789</text:p>
    </table:table-cell>
  </table:table-row>
  <table:table-row table:style-name="ro1">
    <table:table-cell table:style-name="ce15" office:value-type="string" calcext:value-type="string">
      <text:p>Jane Doe</text:p>
    </table:table-cell>
  </table:table-row>
  <table:table-row table:style-name="ro2">
    <table:table-cell table:style-name="ce16" office:value-type="string" calcext:value-type="string">
      <text:p>(234) 567-8901</text:p>

推荐答案

如果每个text()都需要一个li,请更改要迭代的内容.而不是在for循环中选择text(),而是遍历每个text():

If you want an li for each of the text(), then alter what you are iterating over. Instead of selecting the text() inside of the for loop, iterate over each of the text():

xquery version "3.0";
declare namespace office="urn:oasis:names:tc:opendocument:xmlns:text:1.0";

<ul>
{
for $foo  in db:open("foo")//text()[not(matches(., '[0-9]'))]
return <li>{$foo}</li>
}
</ul>

这篇关于如何使用FLOWR和XQuery创建新的列表项?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆