sortby bug or user-buggy ?

Hi everyone !!
I’m having a trouble with sort clause
Here is a sample:

declare namespace tf = ‘http://namespaces.softwareag.com/tamino/TaminoFunction
(
for $q in input()/Establecimiento
sortby
($q/DefinicionEstablecimiento/Nombre ascending,
$q/DefinicionEstablecimiento/Direccion descending)
return
{$q/*}
)
[(position() >= 0) and (position() <= 3)]

I have the error:
<ino:message ino:returnvalue=“6359”>
<ino:messagetext ino:code=“INOXQE6359”>Variable undefined</ino:messagetext>
ino:messagelineVariable: q; line 5, column 2: </ino:messageline>
</ino:message>

The error dissapears when I insert a line like
where ($q/DefinicionEstablecimiento/Nombre != ‘*’) just before sortby clause.
I mean: the query works only if I have a where inside …

I’m wrong?? How can I put it to work??

I have Tamino 4.2.1 Update 7 + 709 hotfix

Yours
Joe

Hi Joe,

The “sort by” in your query belongs to the right hand side of the “for” clause. This means it sorts the result of the path expression “input()/Establecimiento”. Since the variable $q is bound by the “for” clause, it is out of the scope of the “sort by”. So, the error message is correct. You can get around this problem by restating the query in the following way:

declare namespace tf = ‘http://namespaces.softwareag.com/tamino/TaminoFunction
(
for $q in input()/Establecimiento
sortby
(./DefinicionEstablecimiento/Nombre ascending, ./DefinicionEstablecimiento/Direccion descending)
return
{$q/*}
)
[(position() >= 1) and (position() <= 3)]

Now the “sort by” references the context item of the path expression. By the way, please note that in XQuery the first position in a sequence has the index “1” not “0”!

Regards,

Thorsten

Thanks Thorsten
It works now :smiley:
Have a great day !!
Joe