|
From: Sascha G. <gr...@bb...> - 2025-04-23 11:27:23
|
Dear Pieter, dear Peter,
thanks a lot for your suggestions! I tried out Pieters
util:declare-options() solution and it seems to work fine so far. For
documentations sake, here is the updated/fixed version of my attempt:
xquery version "3.1";
let $p_format := request:get-parameter("format", ())
let $test :=
<html>
<head>
<title>Test Title</title>
</head>
<body>
<h1>Hello, World!</h1>
</body>
</html>
return
if ($p_format = "tei-xml") then
(util:declare-option("exist:serialize", "method=xml"), $test) else
(util:declare-option("exist:serialize", "method=html5
media-type=text/html"), $test)
Serialization, doctype and Content-Type header look good with this variant.
Thanks a lot!
Sascha
Am 17.04.2025 um 15:25 schrieb Sascha Grabsch via Exist-open:
> Dear list members,
>
> I'm trying to output different formats (XML and HTML5) from a single
> xquery script, but can't get it to work. Here is my test case:
>
> xquery version "3.1";
> let $p_format := request:get-parameter("format", ())
>
> let $test :=
> <html>
> <head>
> <title>Test Title</title>
> </head>
> <body>
> <h1>Hello, World!</h1>
> </body>
> </html>
>
> return
> if ($p_format = "tei-xml") then (serialize($test, map { "method":
> "xml" })) else (serialize($test, map { "method": "html" }))
>
>
> However in both cases this does not work as expected:
>
> method:xml - The serialization option method:xml does not return valid
> XML, since the returned document is wrongly escaped
> (<html><head><title>Test Title</title></
> head><body><h1>Hello, World!</h1></body></
> html>). The content-type in the response header however is correct
> ("application/xml").
>
> method:html - While the serialization option method:html correctly adds
> a doctype for HTML5 (i. e. <!DOCTYPE html>), the actual response in a
> browser is wrongly escaped (as in <!DOCTYPE html>
> <html><head><title>Test Title</title></
> head><body><h1>Hello, World!</h1></body></
> html>). Additionally the content-type in the response header is
> "application/xml" instead of "text/html".
>
>
> According to <https://exist-db.org/exist/apps/doc/xquery.xml#fn-
> serialize> I would have expected to be able to return different
> serializations via fn:serialize, but it seems it is only possible to
> have one serialization per XQuery script via "declare option
> exist:serialize ..."?
>
> I would be glad about any information or hints what I might be missing.
>
> Thanks a lot!
>
> Sascha
|