Hi Hans-Jürgen,
I had a similar problem 2 weeks ago where I needed to be flexible with a public identifier in serialization, and I switched from %output:doctype-public to serialize(…, map{'doctype-public': if ($niso-version = '1.2') then $tr:niso-1-2-public-identifier else $tr:niso-1-0-public-identifier, 'doctype-system': 'NISO-STS-interchange-1-mathml3.dtd', 'indent': 'no'} ) as the function’s output. Maybe you can also use serialize() inside your function?
Gerrit
On 19.01.2023 15:20, Hans-Jürgen Rennau wrote:
Hello,
I encounter a problem with a RESTXQ application, perhaps someone can help me?
*Goal:* Download a file with an encoding dependent on a user entry. The request contains /form parameters/.
*Attempt:* I can control the encoding using the %output annotation. However, this annotation must be a literal string, I think. Therefore I tried /web:forward/, as well as /web:redirect/, thus triggering the execution of a function with the desired %output declaration.
*Issue:* the form parameters get lost.
How to achieve the goal? Thank you for your advice.
With kind regards, Hans-Jürgen
declare %output:method("text") %output:encoding("utf-8") %rest:path("*/util/download/text*") %rest:form-param("text", "{$text}", "") %rest:form-param("file-name", "{$fileName}", "text.txt") %rest:form-param("encoding", "{$encoding}", "utf-8") function *f:downloadText*( $text as xs:string, $fileName as xs:string, $encoding as xs:string) { if ($encoding eq 'cp1252') then *web:forward*('*/util/download/text-cp1252*') else ... declare %output:method("text") %output:encoding("cp1252") %rest:path("*/util/download/text-cp1252*") %rest:form-param("text", "{$text}", "") %rest:form-param("file-name", "{$fileName}", "text.txt") function *f:downloadTextCp1252*( $text as xs:string, $fileName as xs:string) { let $text := replace($text, '
', '
') return ( rest:response <http:response status="200"> <http:header name="Content-Disposition" value='attachment; filename="{$fileName}"'/> <http:header name="Content-Language" value="en"/> <http:header name="Content-Type" value="text/csv; charset=cp1252"/> </http:response> </rest:response>, $text ) };
PS: The http:header seems to be without effect - experiments seemd to show that I have to use the %output declaration.