XQUERY FLWOR using internal document.

Issues related to W3C XQuery.
kristerskl
Posts: 1
Joined: Sun Feb 20, 2022 4:15 pm

XQUERY FLWOR using internal document.

Post by kristerskl »

Im using http://xpatheval.apphb.com/ for this, so XML and XQUERY is basically in the same file.

And since I need to use FLWOR I don't know how I should approach the part where I need to locate doc() and it cant be empty

My XML:

<?xml version="1.0"?>
<RIGA>
<STREET Name="Brivibas">
<HOUSE No="1">
<FLAT No="1">
<INHABITANT Year="1970" Gender="M">Ivanovs Sergejs</INHABITANT>
<INHABITANT Year="1970" Gender="F">Ivanova Anna</INHABITANT>
</FLAT>
<FLAT No="2">
<INHABITANT Year="1972" Gender="M">Strods Janis</INHABITANT>
<INHABITANT Year="1972" Gender="F">Strode Inna</INHABITANT>
<INHABITANT Year="1974" Gender="F">Strode Julija</INHABITANT>
</FLAT>
</HOUSE>
<HOUSE No="2">
<FLAT No="1">
<INHABITANT Year="1974" Gender="M">Zemzars Uldis</INHABITANT>
</FLAT>
</HOUSE>
</STREET>
<STREET Name="Elizabetes">
<HOUSE No="1">
<FLAT No="1">
<INHABITANT Year="1985" Gender="M">Celms Juris</INHABITANT>
</FLAT>
<FLAT No="2">
<INHABITANT Year="1988" Gender="M">Dmitrijevs Igors</INHABITANT>
<INHABITANT Year="1988" Gender="F">Dmitrijeva Svetlana</INHABITANT>
<INHABITANT Year="1989" Gender="F">Dmitrijeva Olga</INHABITANT>
<INHABITANT Year="1989" Gender="M">Dmitrijevs Pjotrs</INHABITANT>
</FLAT>
</HOUSE>
</STREET>
</RIGA>

I haven't written anything in XQUERY since I dont know how to grab information but my Goal is to have this output using FLWOR system (for, where, order by, return):

<MALES>
<MALE>First name Last name</MALE>
<MALE>First name Last name</MALE>
<MALE>First name Last name</MALE>
<MALE>First name Last name</MALE>
<MALE>First name Last name</MALE>
<MALE>First name Last name</MALE>
</MALES>
adrian
Posts: 2779
Joined: Tue May 17, 2005 4:01 pm

Re: XQUERY FLWOR using internal document.

Post by adrian »

Hi,

XQuery looks like this:

Code: Select all

<MALES>
{for $name in doc("input.xml")/RIGA/STREET/HOUSE/FLAT/INHABITANT[@Gender="M"]/text()
return <MALE>{$name}</MALE>}
</MALES>
Regards,
Adrian
Adrian Buza
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com
Post Reply