Hi,
I have a repeated table with 6 date fields in a record and need to determine the latest of these per record.
For numeric fields this is simple by using the MAX function in default value of the target field: xdMath:Max(../my:dt1 | ../my:dt2 | ../my:dt3 | ../my:dt4 | ../my:dt5 | ../my:dt6)
Unfortunately, MAX does not work for date fields.
Any idea how this can be done efficiently?
I have developed an approach which however seems to me very complicated and I doubt it cannot be done easier:
The approach is to do pairwise comparisons of dates:
dt12max=maximum(dt1,dt2)
dt34max=maximum(dt3,dt4)
dt56max=maximum(dt5,dt6)
dt1234max=maximum(dt12,dt34)
dtdt123456max=maximum(dt1234,dt56)
... where each comparison would look like the statement below - which is kind of a if/then statement using the string-compare function for the actual comparison:
concat(substring(string(../my:dt2), 1, number(0 > (msxsl:string-compare(../my:dt1, ../my:dt2))) * string-length(string(../my:dt2))), substring(string(../my:dt1), 1, number(not(0 > (msxsl:string-compare(../my:dt1, ../my:dt2)))) * string-length(string(../my:dt1))))
This approach works but needs 5 help variables and a long xpath statement in each variables default value.
I attach the xsn and the xml file. In the third repeated table (group4) DTMax is the target field for the comparison of dt1 to dt6. DTMax12 is the target field for my own complex approach for comparing dates dt1 and dt2.
Is there a simpler way to perform multiple dates to determine the latest one?
Regards
Andreas