Search code examples
xquery

Unable to understand this xquery statement


I am new to xquery and unable to understand what does it means :

$bottles=getallBottles()
$cups=getallCups()

<containers>
{
($bottles,$cups)  //this line i am unable to get
}
<containers>

Solution

  • The comma forms a sequence. Presumably $bottles is a sequence of zero-to-many items and $cups is a sequence of zero-to-many items. The comma forms a sequence of all of the items in $bottles and all of the items in $cups.

    For example:

    let $x := (1, 2, 3)
    let $y := ('a', 'b', 'c')
    return ($x,$y)
    

    yields:

    1 2 3 a b c
    

    In the above example, the parentheses are necessary so that forming the sequence of $x, $y takes precedence over return and the entire constructed sequence is returned.

    In an example similar to the original question, parentheses are unnecessary because precedence is not ambiguous:

    let $x := <a><x>5</x><x>6</x></a>
    let $y := <b><y>1</y><y>2</y></b>
    return <container>{$x, $y}</container>
    

    yields:

    <container><a><x>5</x><x>6</x></a><b><y>1</y><y>2</y></b></container>