On 2020-02-19 6:10 a.m., Martin Honnen wrote:
Am 19.02.2020 um 15:08 schrieb thufir:
How can I start a new "record" and then nest tags in that record?


but I'm getting output like:

<xml>
  <record>
      if (matches($line, "[0-9]"))
      then <data>people</data>
      else <name>people</name>
  </record>
  <record>
      if (matches($line, "[0-9]"))
      then <data>joe</data>
      else <name>joe</name>
  </record>
..

wheras I just want output like:

<record>
  <name>joe</name>
  <data>123</data>
</record>


the query:

xquery version "3.0";

<xml>
{
for $line in db:open("foo.txt")//text()
return
        <record>


Nest any contained expression in further curly braces

   {

      if (matches($line, "[0-9]"))
      then <data>{$line}</data>
      else <name>{$line}</name>


}

</record>
}
</xml>




that was quite helpful, thanks.  I'm getting:


    <name>joe</name>
  </record>
  <record>
    <data>phone1</data>
  </record>
  <record>
    <data>phone2</data>
  </record>


and want to only open the new record tab for something like:


<record>
    <name>joe</name>
    <data>phone1</data>
    <data>phone2</data>
</record>


but get "incomplete if statement" when I try to add open and close record tags inside each if statement.

xquery version "3.0";

<xml>
{
for $line in db:open("foo.txt")//text()
return
<record>
{
       if (matches($line, "[0-9]"))
       then <data>{$line}</data>
       else <name>{$line}</name>
}
 </record>
}
 </xml>




thanks,

Thufir

Reply via email to