for each loop
File: Data.xml
<?xml version="1.0"?>
<cars>
<car>A</car>
<car>B</car>
<car>C</car>
<car>D</car>
</cars>
File: Query.xquery
<cars>
{for $i in (1,2,3,4) return <car>{$i}</car>}
</cars>
Output:
<?xml version="1.0" encoding="UTF-8"?>
<cars>
<car>1</car>
<car>2</car>
<car>3</car>
<car>4</car>
</cars>
Related examples in the same category