You can use the XQuery 3.0 function function-lookup
to check the existence of implementation-specific functions to check for the processors. All XQuery 3.0 supporting processors should be able to process this.
declare function local:exist() as xs:boolean {
try {
if (not(empty(function-lookup(xs:QName('system:get-version'), 0))))
then true()
else false()
} catch * {
false()
}
};
(: works only on Saxon PE and EE, fails in HE since HE does not support XQuery 3.0. It would be nice if saxon had a version function. :)
declare function local:saxon() as xs:boolean {
try {
if (not(empty(function-lookup(xs:QName('saxon:parse'), 1))))
then true()
else false()
} catch * {
false()
}
};
declare function local:marklogic() as xs:boolean {
try {
if (not(empty(function-lookup(xs:QName('xdmp:xquery-version'), 0))))
then true()
else false()
} catch * {
false()
}
};
declare function local:basex() as xs:boolean {
try {
if (not(empty(function-lookup(xs:QName('prof:time'), 1))))
then true()
else false()
} catch * {
false()
}
};
declare function local:get-processor() as xs:string {
if (local:exist()) then "eXist"
else if (local:saxon()) then "Saxon"
else if (local:marklogic()) then "MarkLogic"
else if (local:basex()) then "BaseX"
else "Unknown"
};
local:get-processor()
Unfortunately, I was not able to make this more elegant using Higher-Order functions, as the implementation-specific functions were executed before the function is actually called. But I am sure this could also be written more elegant.