On Feb 22, 2025, at 5:33 AM, Christian Grün christian.gruen@gmail.com wrote:
declare %rest:POST %rest:path('out') %rest:form-param('text', '{$text}') %output:method('html') function local:out($text) {
<html>Codepoints: { string-to-codepoints($text) }</html> };
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.
Thanks for your reply —Brian
—— Code -----
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
Echo Request
These are the variables and parmaters available through the request.
Request Variables
Variable Value Method: POST Scheme: http Host: 127.0.0.1 Port: 8080 Path: /printenv Query: URI: http://127.0.0.1:8080/printenv Context: Remote Host: 127.0.0.1 Remote Addres: 127.0.0.1 Request Parameters
Param Value uri ripple name kdkdk email dkdk@kdkdk comment One Two three Request Headers
Header Value Origin http://localhost Accept text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8 Priority u=0, i User-Agent Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/18.3 Safari/605.1.15 Referer http://localhost/dev-pages/comments/comment-form.html X-Forwarded-Host localhost Connection keep-alive Sec-Fetch-Site same-origin Sec-Fetch-Dest document Host 127.0.0.1:8080 Accept-Encoding gzip, deflate Sec-Fetch-Mode navigate Upgrade-Insecure-Requests 1 X-Forwarded-For ::1 Accept-Language en-US,en;q=0.9 Content-Length 84 X-Forwarded-Server MB-15.local Content-Type application/x-www-form-urlencoded Request Cookies
Cookie Value Request Attributes
Attribute Value