sqlxmlxsdxqueryxquery-sql

Equivalent to AS in XQuery?


Is there anyway in xquery to do like in sql: "SELECT name AS buyer"?

enter code here
let $stars := doc("stars.xml")
for $s in $stars/Stars/star
where $s/Address/Street eq "123 Maple St."
return $s/(Name **AS buyer** |cost)

output something like:
<Buyers>
<buyer name=”Ash”><cost>40</cost></buyer>
...
</Buyers>

Solution

  • Instead of return $s/(Name **AS buyer** |cost), I think you want e.g. return <buyer Name="{$s/Name}">{$s/cost}</buyer>.