Skip to content

Instantly share code, notes, and snippets.

@mblakele
mblakele / xqut-sample.xqy
Created November 2, 2011 00:06
XQUT sample invocation
xdmp:invoke(
'xqut.xqy',
(xs:QName('SUITE'),
xdmp:document-get(
"/Users/mblakele/Source/mblakele-xqut/test/test.xml")),
<options xmlns="xdmp:eval">
<root>/Users/mblakele/Source/mblakele-xqut/src/</root>
</options>)
@mblakele
mblakele / xqut-sample.xml
Created November 2, 2011 00:09
XQUT sample test suite
<suite xmlns="com.blakeley.xqut">
<unit result="1">1 + 1</unit>
<unit>
<expr>1 + 1</expr>
<result>2</result>
</unit>
</suite>
@mblakele
mblakele / gist:1342270
Created November 6, 2011 00:51
W3C XQuery 3.0 - Documents for Group By Use Cases
xdmp:document-insert(
'products.xml',
<products xsi:noNamespaceSchemaLocation="products.xsd">
<product>
<name>broiler</name>
<category>kitchen</category>
<price>100</price>
<cost>70</cost>
</product>
<product>
@mblakele
mblakele / gist:1342274
Created November 6, 2011 00:53
W3C XQuery 3.0 - Group By Use Cases Q1
<sales-qty-by-product>{
for $sales in doc("sales-records.xml")/*/record
let $pname := $sales/product-name
group by $pname
order by $pname
return
<product name="{$pname}">{
sum($sales/qty)
}</product>
}</sales-qty-by-product>
@mblakele
mblakele / gist:1342278
Created November 6, 2011 00:55
W3C XQuery 3.0 - Group By Use Cases Q1 Results
<sales-qty-by-product>
<product name="blender">250</product>
<product name="broiler">20</product>
<product name="shirt">10</product>
<product name="socks">510</product>
<product name="toaster">200</product>
</sales-qty-by-product>
@mblakele
mblakele / gist:1342280
Created November 6, 2011 00:56
W3C XQuery 3.0 - Group By Use Cases Q1, using distinct-values
<sales-qty-by-product>{
for $pname in distinct-values(
doc("sales-records.xml")/*/record/product-name)
order by $pname
return
<product name="{$pname}">{
sum(
doc("sales-records.xml")/*/record[
product-name eq $pname ]/qty)
}</product>
@mblakele
mblakele / gist:1342282
Created November 6, 2011 00:58
W3C XQuery 3.0 - Group By Use Cases Q1, using map:map
<sales-qty-by-product>{
let $m := map:map()
let $build :=
for $sales in doc("sales-records.xml")/*/record
let $pname := $sales/product-name
return map:put(
$m, $pname, sum((
map:get($m, $pname),
$sales/qty)))
for $pname in map:keys($m)
@mblakele
mblakele / gist:1342287
Created November 6, 2011 01:00
W3C XQuery 3.0 - Group By Use Cases Q2
<result>{
for $sales in doc("sales-records.xml")/*/record
let $state := doc("stores.xml")/*/store[store-number = $sales/store-number]/state
let $category := doc("products.xml")/*/product[name = $sales/product-name]/category
group by $state, $category
order by $state, $category
return
<group>
{$state, $category}
<total-qty>{sum($sales/qty)}</total-qty>
@mblakele
mblakele / gist:1342290
Created November 6, 2011 01:01
W3C XQuery 3.0 - Group By Use Cases Q2 Results
<result>
<group>
<state>CA</state>
<category>clothes</category>
<total-qty>510</total-qty>
</group>
<group>
<state>CA</state>
<category>kitchen</category>
<total-qty>170</total-qty>
@mblakele
mblakele / gist:1342291
Created November 6, 2011 01:02
W3C XQuery 3.0 - Group By Use Cases Q2, using map:map
<result>{
let $m := map:map()
let $build :=
for $sales in doc("sales-records.xml")/*/record
let $state := doc("stores.xml")/*/store[
store-number = $sales/store-number]/state
let $category := doc("products.xml")/*/product[
name = $sales/product-name]/category
let $key := concat($state, '|', $category)
return map:put(