modify exist option argument based on user agent
You can't put xql logic up with the declare statements in the head of the xql file. So, if you need to modify any of those dynamically, here's what you do:
1) hard code in the default case
2) write a function that tests the condition(s) you care about
2) then in the part of the file that is actually processed (and that seems to be anywhere within the root element (e.g. html)), invoke the function and then for each value returned by the function use a util:declare-option statement.
For example, if I want to write out one exist:serialize argument for IE and another one for all other browsers:
1) hard-code the default case (i.e., the one that works for all browsers other than IE) as usual near the top of the file :
declare option exist:serialize "method=html5 media-type=application/xhtml+xml encoding=utf-8 indent=yes doctype-public=''";
2) write a function that tests the condition you care about and put that up at the head of the file too (declare the namespace if necessary):
declare function local:isIE() as xs:boolean{
let $user-agent := request:get-header("user-agent")
return
if (fn:contains($user-agent,"MSIE"))
then (true())
else (false())
};
3) somewhere within the html element invoke the function and re-declare the option:
{if (local:isIE())
then (util:declare-option("exist:serialize", "method=html5 media-type=text/html encoding=utf-8 indent=yes doctype-public='' "))
else ()
}
I'm not sure if there are any constraints or best-practices regarding where to put the test and redeclaration, but in my brief testing it doesn't seem to matter.