modify exist option argument based on user agent

28/09/11

Permalink 03:08:17 pm, by sarneil, 258 words, 217 views   English (CA)
Categories: Activity log; Mins. worked: 90

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.

Pingbacks:

No Pingbacks for this post yet...

FrancoToile

The prime objective of this project is to create a prototype of a searchable digital video library representing francophone culture. It is to be implemented in French 262.

Reports

Categories

September 2014
Sun Mon Tue Wed Thu Fri Sat
 << <   > >>
  1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30        

XML Feeds