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 (http://www.zorba-xquery.com/modules/xml) 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 ",
               $unquanttype));
  xqxq:bind-variable($caster, xs:QName("val"), $value);
  xqxq:evaluate($caster)

The result of that will be the $casted-value. It'd probably be a good idea to 
explicitly call xqxq:delete-query($caster) also.
-- 
https://code.launchpad.net/~zorba-coders/zorba/bug1064978/+merge/150696
Your team Zorba Coders is subscribed to branch lp:zorba.

-- 
Mailing list: https://launchpad.net/~zorba-coders
Post to     : zorba-coders@lists.launchpad.net
Unsubscribe : https://launchpad.net/~zorba-coders
More help   : https://help.launchpad.net/ListHelp

Reply via email to