Indeed if you convert the text string to codepoints and the codepoints back to a string the newlines are present. I’m not sure understand why they don’t show up otherwise.
My solution was to use javascript to insert <br /> tags into the form data before it gets submitted but your method doesn’t require any javascript.
xquery version "3.1";
(: echo-post.xq: Return all data from an HTTP post to the caller. :)
module namespace comments = "https://kennison.name/comments";
declare
%rest:path("/printenv")
%rest:GET
%rest:POST
%output:method("html")
%output:media-type("text/html")
function comments:echo-post(){
let $method := request:method()
let $scheme := request:scheme()
let $host := request:hostname()
let $port := request:port()
let $path := request:path()
let $query := request:query()
let $uri := request:uri()
let $context := request:context-path()
let $address := request:address()
let $remote-host := request:remote-hostname()
let $remote-address := request:remote-address()
let $remote-port := request:remote-port()
return
<html>
<head>
<title>Print Environ</title>
<link rel="stylesheet" href="http://localhost/assets/css/jdoe.css"/>
<link rel="stylesheet" href="http://localhost/assets/css/jdoe2.css"/>
<style>
<![CDATA[
th, td {
border: 1px solid black;
padding: 8px;
margin-left:10px;
}
thead th {
width: 25%;
}]]>
</style>
</head>
<body>
<section id="home">
<article>
<h1>Echo Request</h1>
<p> These are the variables and parmaters available through the request.</p>
<h3>Request Variables</h3>
<table>
<thead>
<tr><th>Variable</th><th>Value</th></tr>
</thead>
<tbody>
<tr><td>Method:</td><td>{$method}</td></tr>
<tr><td>Scheme:</td><td>{$scheme}</td></tr>
<tr><td>Host:</td><td>{$host}</td></tr>
<tr><td>Port:</td><td>{$port}</td></tr>
<tr><td>Path:</td><td>{$path}</td></tr>
<tr><td>Query:</td><td>{$query}</td></tr>
<tr><td>URI:</td><td>{$uri}</td></tr>
<tr><td>Context:</td><td>{$context}</td></tr>
<tr><td>Remote Host:</td><td>{$remote-host}</td></tr>
<tr><td>Remote Addres:</td><td>{$remote-address}</td></tr>
</tbody>
</table>
<h3>Request Parameters</h3>
<table>
<thead>
<tr><th>Param</th><th>Value</th></tr>
</thead>
<tbody>
{
for $p in request:parameter-names()
return
<tr><td>{$p}</td><td>{request:parameter($p)}</td></tr>
}
</tbody>
</table>
<h3>Request Headers</h3>
<table>
<thead>
<tr><th>Header</th><th>Value</th></tr>
</thead>
<tbody>
{
for $h in request:header-names()
return
<tr><td>{$h}</td><td>{request:header($h)}</td></tr>
}
</tbody>
</table>
<h3>Request Cookies</h3>
<table>
<thead>
<tr><th>Cookie</th><th>Value</th></tr>
</thead>
<tbody>
{
for $c in request:cookie-names()
return
<tr><td>{$c}</td><td>{request:cookie($c)}</td></tr>
}
</tbody>
</table>
<h3>Request Attributes</h3>
<table>
<thead>
<tr><th>Attribute</th><th>Value</th></tr>
</thead>
<tbody>
{
for $a in request:attribute-names()
return
<tr><td>{$a}</td><td>{request:attribute($a)}</td></tr>
}
</tbody>
</table>
</article>
</section>
</body>
</html>
};
—— Comment Form -----
Name: Email: Comment:
—— Printed Result ——
—— as you can see the newlines don’t show in results