max. Value and sort by

Hello,
i assumed to get the max.systemId of total systems. So i sort the systemId descending and the first one has the max. systemId. Who has a better idea to get the max. value with xquery?

Furthermore, i’v got an error message with sorting like this:
variable undefined; varable q
-----here is my xquery

for $q in input()/system 
sort by($q/key/systemId descending)
return $q/key/systemId

any suggestion is welcome,

Chacha

XQuery has a “max” function. see “xqueryref/ref-fn_max.htm#ref-fn_max” in your Tamino documentation tree.

indeed,the max function is fine.

Thanks a lot.

But regard to the problem with sort by (see the previous message), i don’t know, why i didn’t get the sorted list.

Hi,
i have solved this problem by myself.
The correct query seems like this:

for $q in input()/system
return $q/key/systemId
sort by(. descending)

or

for $q in input()/system
sort by(./key/systemId descending)
return $q/key/systemId

Chacha