The function can e.g. be called with:
...
response headers [1]. Note that the original result may implicitly be
from within a JavaScript framework.
On Thu, Jan 19, 2023 at 3:20 PM Hans-Jürgen Rennau <
hjrennau@gmail.com> 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.
>