unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
From: Luis Felipe <sirgazil@zoho.com>
To: Richard Sent <richard@freakingpenguin.com>, guile-user@gnu.org
Subject: Re: Removing/Ignoring xmlns when using xml->sxml
Date: Mon, 22 Jul 2024 15:28:21 +0000	[thread overview]
Message-ID: <b8d24e47-388e-ad2c-1390-ddc7666e2f5e@zoho.com> (raw)
In-Reply-To: <875xsy3ytl.fsf@freakingpenguin.com>


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

Hi Richard,

El 22/07/24 a las 3:11, Richard Sent escribió:
> Hi all,
>
> I have some XML created by a tool called latexml that can convert LaTeX
> equations to MathML. I am processing the output of this tool as part of
> a Guile program and will be using it in a website.
>
> The output looks something like this:
>
> --8<---------------cut here---------------start------------->8---
> <math xmlns=\"http://www.w3.org/1998/Math/MathML\" alttext=\"\\frac{1}{2}\" display=\"block\">
>    <mfrac>
>      <mn>1</mn>
>      <mn>2</mn>
>    </mfrac>
> </math>
> --8<---------------cut here---------------end--------------->8---
>
> I need to convert this output to SXML to integrate it with the rest of
> the toolchain.
>
> Annoyingly, when using xml->sxml, the xmlns attribute is prepended to
> every non-default element. For example,
> '(http://www.w3.org/1998/Math/MathML:math ...) [1].
>
> This behavior is undesirable when splicing the MathML into HTML, since
> HTML doesn't support namespaces and web browsers don't seem to handle
> elements with colons. The intended conversion is to simply splice the
> MathML into HTML, sans namespace [2].
>
> xml->sxml has a #:namespaces argument that allows me to alias the URL
> namespace to something else in the SXML, but it doesn't look like I can
> alias it to a "nil" namespace that isn't prepended at all.

The following seems to work (where xml-string is the example you provided):

(define namespaces '((#false . "http://www.w3.org/1998/Math/MathML")))

(xml->sxml xml-string #:namespaces namespaces)
$7 = (*TOP* (math (@ (display "block") (alttext "\\frac{1}{2}")) "\n  " 
(mfrac "\n    " (mn "1") "\n    " (mn "2") "\n  ") "\n"))



[-- 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-07-22 15:28 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-07-22  3:11 Removing/Ignoring xmlns when using xml->sxml Richard Sent
2024-07-22 15:28 ` Luis Felipe [this message]
2024-07-22 23:58   ` Richard Sent

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=b8d24e47-388e-ad2c-1390-ddc7666e2f5e@zoho.com \
    --to=sirgazil@zoho.com \
    --cc=guile-user@gnu.org \
    --cc=richard@freakingpenguin.com \
    /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).