max() : X-Query filtering using max() result

Hello there.

I am facing an issue with the max() function.
My doctype looks like the following :




OK, so i have numerous projects = XML documents inside Tamino. The same project (having same name) can be versionned : the xml document is cloned and version tags values modified accordingly.

Anyway, what I want is to fetch the latest XML document which is the latest version.

My X-Query is the following (it is simplified - ie only the latest major version)


=> give me ALL project666 documents.

The following :


=> give me


So I tried with hard-coded value (3 is the latest major version)


=> It gives me what I want : the latest major version xml document.

I even have tried stuff like number(max(/…)), without success.

So my point is, can you use the max() function inside a X-Query filter ?

Thanks in advance.

Bertrand Martel
Software AG France

Hello Bertrand,

I don’t know if this is helpful in your situation, but this works in Tamino 4.1 XQuery:

   let $maxMajor := max(input()/project[common/name='Project666']/version/major)
   for $project in input()/project
   where $project/common/name='Project666'
     and $project/version/major = $maxMajor
   return $project

I hope that helps,

Hello Bertrand,

X-Query can’t do that since an absolute path in a filter is always interpreted as beginning from the current document and thus the expression provided as the input to max() yields the current major value only. So, yes, you can use max() in a filter but in your case to no avail. As Trevor pointed out you can use XQuery.



Thank you very much for your answers. I have solved my problem inside an XSL template (with EXSLT max() function).
Off course, this (should) take longer than using the max() function directly in the X-Query, but process time is satisfactory. So I’m OK with that.


Bertrand Martel
Software AG France