Saxon 8.1.1 declareVariable problem

Help
2004-12-17
2012-10-08
  • Yana Kadiyska

    Yana Kadiyska - 2004-12-17

    Hello,

    newby here so sorry if this is an obvious mistake. I need to declare a variable that my query uses. I have the following code:

    final Configuration config;
    DynamicQueryContext dynamicContext ;
    StaticQueryContext staticContext;
    //some instantiation here

    dynamicContext.setContextNode(staticContext.buildDocument(
    new DOMSource(dom)) );

    String query="for $a in $root//price return $a";

    Variable thisVar = Variable.make("root");
    thisVar.setValue(dynamicContext.getContextNode() );

    staticContext.declareVariable(thisVar);

    XQueryExpression exp = staticContext.compileQuery(query);

    At which point I get a runtime exception that variable $root is not declared (I know the query is unnecessarily complex but for purposes of my app I prefer not to alter the query). The binding I'm trying to achieve is equivalent to let $root:=doc(...).

    Also, through some debugging, I know the binding makes into the variables map of the static context object...not sure why it's not found when compile is called.

    Thanks for any help

     
    • Michael Kay

      Michael Kay - 2004-12-21

      Your query needs to declare the variable $root as an external variable:

      declare variable $root external;

      Michael Kay
      Saxonica Limited

      (Sorry for the delayed response, SourceForce hasn't been notifying me of these postings)

       

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks