unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
From: Luis Felipe <sirgazil@zoho.com>
To: Maxime Devos <maximedevos@telenet.be>, Guile User <guile-user@gnu.org>
Subject: Re: SXML and optional attributes
Date: Mon, 23 Dec 2024 00:01:25 +0000	[thread overview]
Message-ID: <7c9fdb64-6212-4961-ab39-12060a7c4b9f@zoho.com> (raw)
In-Reply-To: <20241222223817.rxeH2D0032kJuzj01xeHlX@laurent.telenet-ops.be>


[-- Attachment #1.1.1: Type: text/plain, Size: 823 bytes --]

On 22/12/24 21:38, Maxime Devos wrote:
>
> Unquote-splicing (,@) is your friend:
>
> `(foo ,@(if p? '(a (b) c) '()) d)
>
> When p? -> (foo a (b) c d).
>
> When (not p?) -> (foo d).
>
> Now do this for SXML …
>
Ah, splicing... yes Maxime, that works :)

So I applied it as follows:

(define* (special-input #:key name (required? #true))
   "Return an SXHTML INPUT element for typing text."
   `(input
     (@ (type "text")
        (name ,name)
        ,@(if required? '((required "")) '()))))

And now converting to XML I get the results I expected:

(sxml->xml (special-input #:name "author"))
→ <input type="text" name="author" required="" />

(sxml->xml (special-input #:name "author" #:required? #false))
→ <input type="text" name="author" />

Thank you very much,

[-- Attachment #1.1.2: OpenPGP public key --]
[-- Type: application/pgp-keys, Size: 2881 bytes --]

[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 495 bytes --]

      reply	other threads:[~2024-12-23  0:01 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-12-22 21:23 SXML and optional attributes Luis Felipe
2024-12-22 21:38 ` Maxime Devos via General Guile related discussions
2024-12-23  0:01   ` Luis Felipe [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/guile/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=7c9fdb64-6212-4961-ab39-12060a7c4b9f@zoho.com \
    --to=sirgazil@zoho.com \
    --cc=guile-user@gnu.org \
    --cc=maximedevos@telenet.be \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).