Skip to content

Instantly share code, notes, and snippets.

@MikeRalphson
Forked from HakimCassimallyBBC/cumber.xqy
Created July 13, 2016 14:18
Show Gist options
  • Save MikeRalphson/70a41672ab2eea6f83ac595f0e376683 to your computer and use it in GitHub Desktop.
Save MikeRalphson/70a41672ab2eea6f83ac595f0e376683 to your computer and use it in GitHub Desktop.
'cumber sketch
xquery version "1.0-ml";
declare namespace p = "http://ns.webservices.bbc.co.uk/2006/02/pips";
declare namespace n = "http://www.bbc.co.uk/nitro/";
declare namespace nm = "http://www.bbc.co.uk/nitro/meta";
import module namespace mem = "http://xqdev.com/in-mem-update" at "/MarkLogic/appservices/utils/in-mem-update.xqy";
declare function local:tokenize($item) as xs:string* {
typeswitch($item)
case text()
return tokenize( fn:normalize-space( fn:lower-case($item) ), ' ')
case element()
return upper-case( xs:string(node-name($item)) )
default return 'argh'
};
declare function local:xml-to-function-spec($root as element()) {
let $nodes := $root/child::node()
let $count := fn:count($nodes[. instance of element()])
let $function-name := fn:string-join(
for $m in ($root, $nodes) return local:tokenize($m),
'-'
)
return ($function-name, $count)
};
declare function local:GIVEN-we-have-created-OBJECTS($root as element(), $objects as element()) as element() {
(: handwave :)
let $brand := $objects//brand
let $updated-root := mem:node-insert-child($brand, attribute effective-pid { 'bPID1-abcde' })
return ($updated-root)
};
let $x := <given> We have created <objects><brand pid="bPID1" /><episode pid="ePID1" /></objects> </given>
let $spec := local:xml-to-function-spec($x)
return $spec
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment