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

Michael Kay mike at saxonica.com
Fri Jul 13 08:18:08 PDT 2012


Your problem is that the initialization of $models goes down two levels 
below the document node, so it is bound to a sequence of Model elements, 
so when you do $models/* you are selecting the children of the Model 
elements, but there are no child elements to select. Remove a /* either 
from the definition of $models or from the expression where it is used.

Michael Kay
Saxonica

On 13/07/2012 15:41, Ihe Onwuka wrote:
> 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>




More information about the talk mailing list