Skip to content

Instantly share code, notes, and snippets.

@HakimCassimallyBBC
Created September 8, 2015 07:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save HakimCassimallyBBC/2f349b957393f54e34d2 to your computer and use it in GitHub Desktop.
Save HakimCassimallyBBC/2f349b957393f54e34d2 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
@HakimCassimallyBBC
Copy link
Author

NB: on line 18, child:: may not be needed, but node() function is!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment