Multiple different serialization formats in a single xquery
Sascha Grabsch via Exist-open <[email protected]> Thu, 17 Apr 2025 15:25:18 +0200
| Newsgroups | gmane.text.xml.exist |
|---|---|
| Message-ID | <[email protected]> |
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
--
Berlin-Brandenburgische Akademie der Wissenschaften
TELOTA (The Electronic Life Of The Academy)
Jägerstr. 22/23 | 10117 Berlin
[email protected] | +49 30 20370 536
_______________________________________________
Exist-open mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/exist-open