Review: Needs Fixing

1. Need some test cases of this functionality, including error conditions, for 
both new functions.

2. For the element() case, I think you should use the x:parse() function in the 
built-in XML module ( with the 
"parse-external-parsed-entity" option. I'm not sure it'll make a difference, 
honestly, but it's slightly more correct.

3. I agree set-variable() isn't a great name. It should be more explicit that 
it is doing casting. Maybe bind-cast-variable() ?

4. It'd be nice if you could support eg. xs:integer+, and all known schema 
simple types. I have a suggestion - in xqxq:bind-cast-variable(), first check 
for object/array/element/document-node, and then for any other type, use XQXQ 
to let XQuery itself do the casting. You'll need to first strip the quantifier 
from the type string, and then construct a query that does the casting. This 
should work:

  variable $unquanttype := fn:replace($type, "[*?+]$", "");
  variable $caster := xq := xqxq:prepare-main-module(
     fn:concat("declare variable $val as xs:string* external; ",
               "for $v in $val return $v cast as ",
  xqxq:bind-variable($caster, xs:QName("val"), $value);

The result of that will be the $casted-value. It'd probably be a good idea to 
explicitly call xqxq:delete-query($caster) also.
Your team Zorba Coders is subscribed to branch lp:zorba.

Mailing list:
Post to     :
Unsubscribe :
More help   :

Reply via email to