[xquery-talk] Multiple computed attributes in Saxon 8.9

Claus claus.klingberg at gmail.com
Tue May 15 18:36:56 PDT 2007


Hi John,

cheez, you're right - just wrapping the attribute constructors into a
pair of parentheses worked just fine:

Like so:
[...]
            return
            (attribute brand {data($brand/v:Description[@language="deu"])},
              attribute pg {data($pg/v:Description[@language="deu"])},
              attribute series {data($br/v:Description[@language="deu"])}
            )
[...]

Now that you mentioned it, I even found a relevant hint on the topic
in the W3C XQuery 1.0 spec:

[...]
"Parentheses are helpful in return clauses that contain comma
operators, since FLWOR expressions have a higher precedence than the
comma operator. For instance, the following query raises an error
because after the comma, $j is no longer within the FLWOR expression,
and is an undefined variable:

let $i := 5,
    $j := 20 * $i
return $i, $j
[...]

Have to remember that, many Thanks!

Claus


On 5/15/07, John Snelson <john.snelson at oracle.com> wrote:
> Hi Claus,
>
> Interestingly, this exact situation has come up a number of times
> recently on this mailing list. You are having problems with operator
> precedence - and need to enclose all of your attribute constructors in
> parentheses for them to be treated as part of the return expression.
>
> John
>
> Claus wrote:
> > Hi list,
> >
> > I'm using Saxon 8.9.0.3J and I get the following error that puzzles me:
> >
> > Error on line 33 column 37 of file:/c:/work/pue-get-vehicle.xq:
> >  XPST0008: XQuery static error in #...ute pg {data($pg/v:Description#:
> >    Variable $pg has not been declared
> > Static error(s) in query
> >
> > Here is part of the source where the error occurs - line #33 in the error
> > message is line #14 below:
> >
> > [...]
> > 1 <models>
> > 2   {
> > 3     for $model in
> > doc("pue_current/pue-vehicleModelList.xml")//v:VehicleModel
> > 4     let $br :=
> > doc("pue_current/pue-stamm-br.xml")//v:Series[@ID=$model/@SeriesID]
> > 5     where some $modelbm in $model/v:DesignNumber satisfies
> > ($modelbm/@ID = $bm/@ID)part of the source where the error occurs - line #33 in the error
> message is line #14 below:
>
> [...]
> > 6     return
> > 7     <vehiclemodel>
> > 8       {
> > 9         (: TODO: make use of WHC and Plant attributes as well :)
> > 10         let $pg :=
> > doc("pue_current/pue-stamm-prod.xml")//v:ProductGroup[@ID=$br/@ProductGroupID]
> >
> > 11         let $brand :=
> > doc("pue_current/pue-stamm-marken.xml")//v:Brand[@ID=$br/@BrandID]
> > 12         return
> > 13           attribute brand {data($brand/v:Description[@language="deu"])},
> > 14           attribute pg {data($pg/v:Description[@language="deu"])},
> > 15           attribute series {data($br/v:Description[@language="deu"])}
> > 16       }
> > 17     </vehiclemodel>
> > 18   }
> > 19 </models>
> > [...]
> >
> > What really irritates me is that I can resolve the error by either deleting
> > line #14 (which seems reasonable) *or* by deleting line #13 (!!).
> >
> > The error message says I haven't declared variable $pg, but I thought I did
> > in line #10. Removing line #14 obviously works, but so does removing line
> > #13. Looks like XQuery won't allow me to have more than two computed
> > attributes following each other.
> >
> > What am I missing here?
> >
> > Thanks,
> > Claus
> > _______________________________________________
> > talk at x-query.com
> > http://x-query.com/mailman/listinfo/talk
>
>


-- 

Mit freundlichem Gruß,
Claus Klingberg



More information about the talk mailing list