[xquery-talk] Simple (I thought) Xquery giving run-time error.

Ihe Onwuka ihe.onwuka at googlemail.com
Fri Jul 13 07:41:50 PDT 2012


Given this in modelNames.xml

<?xml version="1.0"?>
<ModelNames xmlns="http://www.b2b.net/plants">
  <Model singular="sale">sales</Model>
  <Model singular="stock">stocks</Model>
  <Model singular="plant">plants</Model>
  <Model singular="client">clients</Model>
</ModelNames>

I am having problems with the following XQuery

xquery version "1.0";


declare namespace b2b = "http://www.b2b.net/plants";
declare namespace xf="http://www.w3.org/2002/xforms";
declare namespace html="http://www.w3.org/1999/xhtml";
declare namespace ev="http://www.w3.org/2001/xml-events";

declare variable $configDir as xs:string :="config";

declare variable $models as element()*
:=doc(concat($configDir,"/modelNames.xml"))/*/*;

declare function local:bindModel($x,$y,$z) {$x};

declare function local:capitalise($str)
{
    concat(upper-case(substring($str,1,1)),substring($str,2))
};

declare function local:defineModelRoot($model as element())
{
   element {concat('b2b:',local:capitalise($model/text()))}
            {element xf:bind {attribute repeat
{local:getBindingFileName($model)}}}
};

declare function local:getBindingFileName($model as element()) as xs:string
{
   concat($model/@singular,'Bindings.xml')
};
    <switch xmlns="http://www.w3.org/2002/xforms">
      {$models/*/<case
id='{text()}Case'>{local:bindModel(local:defineModelRoot(.),"",xs:QName('group'))}</case>}
    </switch>

The idea of  the line that says

  {$models/*/<case
id='{text()}Case'>{local:bindModel(local:defineModelRoot(.),"",xs:QName('group'))}</case>}

is for the <case> direct constructor to be evaluated for each model
element in $models. The two substitutions I am hoping for is the
text() element in the AVT for the id attribute of the case element and
the . in local:defineModelRoot, which is meant to pass the context
model element as a parameter to local:defineModelRoot.

Is my understanding of what I should expect incorrect. If so I would
appreciate an explanation rather than just a solution.

thanks.


More information about the talk mailing list