groupingdata-extractionxmltableflworshred

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


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>

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

Preferred output would be of the form:

Most likely the data is problematic in some way, because a slightly different 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?

An excerpt of the data:

 <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>

Solution

  • 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>