首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何使用FLOWR和XQuery创建新的列表项?

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

Stack Overflow用户
提问于 2020-02-14 15:18:55
回答 2查看 69关注 0票数 1

我希望从一个XML文件中选择非数值数据,将其分解成数据库列,或者至少是一个xmltable-like结构。这个FLWOR给出了一个有点有用的结果:

代码语言:javascript
复制
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标记中,如下所示:

  • a、b、c、d

优先输出的形式如下:

  • 一个
  • B

很可能是数据有问题在某种程度上,因为一个稍微不同的FLOWR

代码语言:javascript
复制
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]'))]

当然,在一个新的行上输出每个非数字字符串。如何将其输出到列表中?

数据摘录:

代码语言:javascript
复制
 <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>
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2020-02-15 16:20:06

如果您想要为每个litext(),然后改变您要迭代的内容。而不是在for循环中选择text(),而是迭代每个text()

代码语言:javascript
复制
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
EN

Stack Overflow用户

发布于 2020-02-15 17:17:55

只为完整起见:

产出:

  • 人民

phone1phone2phone3

cell4home5

  • 爱丽丝

atrib6x7y9z10

查询:

代码语言:javascript
复制
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>

如果这对其他人有利。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/60229052

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档