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.