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

Josh Spiegel josh.spiegel at oracle.com
Fri Jul 13 08:20:41 PDT 2012


It seems like you might have too many '/*' steps.  For example, if you evaluate $models/* in the body, I think you should get the empty sequence.  $models appears to bind to the sequence of <Model> elements so $models/* would select element children of each but there aren't any.

I would try changing your line to the following:

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

Josh

On Jul 13, 2012, at 7:41 AM, Ihe Onwuka wrote:

> 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.
> _______________________________________________
> talk at x-query.com
> http://x-query.com/mailman/listinfo/talk




More information about the talk mailing list