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

Hello there.

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



Project666
<…>


2
1
0

<…>


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)

/project[common/name=‘Project666’][version/major=max(/project[common/name=‘Project666’]/version/major)]

=> give me ALL project666 documents.

The following :

max(/project[common/name=‘Project666’]/version/major)

=> give me

xql:result3</xql:result>

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

/project[common/name=‘Project666’][version/major=3]

=> 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,
Trevor.

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.

Regards,
Juliane.

Hello,

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.

Ciao.

Bertrand Martel
Software AG France