issue with function return types
Created by: peterstadler
There seems to be a changed behavior with eXist versions > 6.0.1 that now ()/string(@foo)
returns an empty-sequence, not a string. Saxon also processes it that way so I believe it to be in alignment with the specs ;)
Various functions in edition.xqm rely on the old buggy behavior, e.g. https://github.com/Edirom/Edirom-Online/blob/ab873e092af1aea89c68d2b1135b856448476f5b/add/data/xqm/edition.xqm#L93-L96
That is, when doc($uri)//edirom:preferences
evaluates to the empty sequence, the whole expression will return an empty sequence which is not what the function return type says, hence an error will be raised.
This happens in the Edirom when no resolvable $uri
(= $uri equals the empty string) is passed to the function – which is another issue because Edirom relies on some buggy eXist behavior, see https://github.com/eXist-db/exist/issues/3898
Since this affects a lot of functions and I do not have the needed overview, I can only suggest to
a) wrap the fn:doc
function in a custom function that checks doc-available
first (and/or wraps it in a try/catch)
b) replace occurrences of some/xpath/string(@someAttribute)
with some/xpath/@someAttribute => string()