如何使用 FLOWR 和 XQuery 创建新的列表项?

How to create a new list item with FLOWR and XQuery?

我正在寻找 select 来自 XML 文件的非数字数据,以便将其分解成数据库列,或者至少是一个类似 xmltable 的结构。 FLWOR 给出了一个有用的结果:

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标签中,例如:

首选输出格式为:

在某种程度上很可能是 data is problematic,因为 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]'))]

肯定会在新行上输出每个非数字字符串。我如何将其输出到 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():

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>

仅为完整性:

输出:

    • 电话 1
      手机2
      电话 3
  • 起诉
    • cell4
      家5
  • 爱丽丝
    • atrib6
      x7
      y9
      z10

查询:

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

<ul>
{
for $line in db:open("people")//text()
return
      if (matches($line, "[0-9]"))
      then <ul>{$line}</ul>
      else <li>{$line}</li>
}
</ul>

这对其他人有好处吗?