declare namespace w = "xdsconfig.to.wsdl"; declare variable $ws-name external; declare variable $global-config external; declare variable $local-config external; declare variable $ws-url external; (: -------------------------------------------- pass-thru to make the fn:normalize() name shorter. $s - the string to normalize -------------------------------------------- :) declare function local:n($s){ fn:normalize-space($s) }; (: -------------------------------------------- Translate a QN (as defined in XQS config schema) into a qualified name. if ns is declared here explicitly, use ns else call local:make-prefix() to construct a prefix with the QN's prefix and (possibly) bindings. $q - the QN to parse $bp - list of elements -------------------------------------------- :) declare function local:parse-QN($q, $bp){ if($q/@namespace and $q/@type) then fn:concat(fn:concat($q/@namespace,":"), local:n($q/@type)) else if($q/@namespace) then fn:concat(fn:concat($q/@namespace,":"), local:n($q/text())) else if($q/@type) then fn:concat(local:make-prefix($q/@prefix, $bp), local:n($q/@type)) else fn:concat(local:make-prefix($q/@prefix, $bp), local:n($q/text())) }; (: -------------------------------------------- Creates Namespace prefix. If prefix is null, returns no prefix, otherwise returns trim(prefix) + ":". SPECIAL CASE 1: if prefix is in , use namespace SPECIAL CASE 2: if prefix points to xs, return no prefix $q - the QN $bp - list of elements -------------------------------------------- :) declare function local:make-prefix($p, $bp){ let $x := local:n($p) return if($x eq "") then "" else let $pfx := $bp[@prefix eq $x] return if($pfx) then if($pfx eq "http://www.w3.org/2001/XMLSchema") then "" else fn:concat($pfx, ":") else fn:concat($x, ":") }; (: -------------------------------------------- Determine function's namespace if function-name of config element uses @namespace - return it else resolve the prefix to the namespace via bindings $fn - the element $bp - list of elements -------------------------------------------- :) declare function local:fn-ns($fn, $bp){ if($fn/@namespace ) then local:n($fn/@namespace) else if($fn/@prefix) then local:n($bp[@prefix eq $fn/@prefix]/text()) else "" }; (: -------------------------------------------- Takes a single xqsview-source element, constructs equivalent WSDL types, elements, and operations. $cfg - an element $bp - list of elements -------------------------------------------- :) declare function local:breakout($cfg, $bp) { let $name := local:n($cfg/function-name/text()) let $fnns := local:fn-ns($cfg/function-name, $bp) return {$fnns} { (: get imported schemas, may be duplicates :) for $s1 in $cfg//schema-type where $s1/@namespace and $s1/@location return , for $s2 in $cfg//output-element where $s2/@namespace return } (: Make complexTypes from input params :) { for $x in $cfg/input-parameters/part return } (: Make complexTypes from output type :) {if(($cfg/output-element/@type and $cfg/output-element/@namespace) or ($cfg/output-element/@type and $cfg/output-element/@prefix)) then else if($cfg/output-element) then else } }; (: ================================================= MAIN MODULE Proceed in 2 steps. 1) for each WSDL-visible function, parse out its input types, output types and schemas. the function local:breakout() does all the work. 2) construct a single WSDL using parts from the returned by step 1). ================================================= :) let $bindprefixes := doc($local-config)//bind-prefix/use-prefix let $blist := ( for $x in doc($local-config)//xqsview-source[@WSDLvisibility="true"] where count($x/dataSource) = 0 return local:breakout($x, $bindprefixes), if($local-config eq $global-config) then () else for $x in doc($global-config)//xqsview-source[ @WSDLvisibility="true"] return local:breakout($x, $bindprefixes) ) let $dist-fn-nses := fn:distinct-values($blist//w:FN-NS/text()) let $ns-map := for $ns in $dist-fn-nses return fnns{fn:index-of($dist-fn-nses, $ns)} {$ns} let $schemas := (for $f-ns in $ns-map let $pf := $f-ns//w:pf/text() let $fns := $f-ns//w:ns/text() return { let $all-nses := for $b in $blist[w:FN-NS/text() eq $fns] where $b/w:IMPORT//@namespace return $b/w:IMPORT//@namespace let $distinctns := fn:distinct-values($all-nses) let $imports := (for $d in $distinctns let $sl := (for $b in $blist[w:FN-NS/text() eq $fns] where $b/w:IMPORT//@namespace eq $d return $b/w:IMPORT//@schemaLocation) return ) let $all-types := (for $b in $blist[w:FN-NS/text() eq $fns] return $b/w:TYPES/* ) return ($imports, $all-types) } ) return {$schemas} {$blist/w:MESSAGES/*} {$blist/w:OPERATIONS/*} {for $o in $blist/w:OPERATIONS/* return }