Re: [xsl] HTML5 and MathML and namespaces, oh my

Subject: Re: [xsl] HTML5 and MathML and namespaces, oh my
From: "Chris Papademetrious christopher.papademetrious@xxxxxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Wed, 4 Nov 2020 22:00:52 -0000
Thanks Wendell!

When I first learned about XSLT and namespaces, I figured, bIbll be
thankful for this when I have mixed-namespace content.b I am relieved that
indeed, the complexity helps avoid even more complexity!

I am learning XSLT and namespaces at the same time. My background is
perl/Tcl/C/etc., and my brain doesnbt think in XSLT yet. Every template,
every structure, every expression is a hard-fought battle.

Thankfully, this list has been outstandingly helpful and patient with my
questions.


  *   Chris


From: Wendell Piez wapiez@xxxxxxxxxxxxxxx
<xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Sent: Wednesday, November 4, 2020 11:12 AM
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject: Re: [xsl] HTML5 and MathML and namespaces, oh my

Chris,

Awesome. You have about cracked the namespace conundrum. Part of the key is to
see that the XSLT is also an XML document and follows all the same rules as
any other XML document as to its namespaces.

So:

> Why would the XSLT serializer write explicit namespace references that
arenbt needed by context?

In this case, all the declarations in samples you have shown are needed with
the exception of the stray binding to an 'mml' prefix, which you removed. They
would not be needed if the processor (say) assigned all its own prefixes to
names, instead of using the names as given in the XSLT. But we would hate
that. So it does its best to give us what we need, with the names it thinks we
want.

> Isnbt the point of namespaces that everything is fully qualified
internally, then the output can adjust accordingly?

Yes! As you've discovered, that can require some jiggery when multiple
vocabularies are competing for unprefixed names (or the same prefixes).

> How do I get a clean <math> island of MathML content without namespace stuff
cluttering up its contents?

Bravo! Actually with a little practice you can make it so your code is
reasonably clean even in mixed-namespace use cases.

Old project:
https://github.com/wendellpiez/XMLNamespaceFixup<https://urldefense.com/v3/__
https:/github.com/wendellpiez/XMLNamespaceFixup__;!!A4F2R9G_pg!Jhl_IDRYqlo2Vz
hBevEPT2OWcoGcLIPmsruLOTbumPfCYoJ_cCkeVydWWU_RjqAl8DdrvKRO1IBfYvM$> (but if
you do things right you'll never need it).

Cheers, Wendell


On Wed, Nov 4, 2020 at 8:04 AM Chris Papademetrious
christopher.papademetrious@xxxxxxxxxxxx<mailto:christopher.papademetrious@syn
opsys.com>
<xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx<mailto:xsl-list-service@xxxxxxxxxxxx
rytech.com>> wrote:
Hi Martin,

Thanks for taking the time to reply!

The :mml namespace was a vestigial declaration from earlier experiments. I
didn't realize its presence would cause problems. After deleting it, I get


    ...
    <math
xmlns="http://www.w3.org/1998/Math/MathML<https://urldefense.com/v3/__http:/w
ww.w3.org/1998/Math/MathML__;!!A4F2R9G_pg!Jhl_IDRYqlo2VzhBevEPT2OWcoGcLIPmsru
LOTbumPfCYoJ_cCkeVydWWU_RjqAl8DdrvKROJrOkqso$>">
      <mrow>
        <mrow xmlns="">
          <mspace
xmlns="http://www.w3.org/1998/Math/MathML<https://urldefense.com/v3/__http:/w
ww.w3.org/1998/Math/MathML__;!!A4F2R9G_pg!Jhl_IDRYqlo2VzhBevEPT2OWcoGcLIPmsru
LOTbumPfCYoJ_cCkeVydWWU_RjqAl8DdrvKROJrOkqso$>"/>
        </mrow>
      </mrow>
    </math>
    ...


which makes me now realize that my newly-added <mrow> was *not* in the MathML
namespace as I expected. So then I added

    xmlns="http://www.w3.org/1998/Math/MathML<https://urldefense.com/v3/__htt
p:/www.w3.org/1998/Math/MathML__;!!A4F2R9G_pg!Jhl_IDRYqlo2VzhBevEPT2OWcoGcLIP
msruLOTbumPfCYoJ_cCkeVydWWU_RjqAl8DdrvKROJrOkqso$>"

to my <xsl:stylesheet> opening tag so that the unqualified <mspace> in my
template was created in the MathML namespace, and now I get the expected
results:


<!DOCTYPE html>
<html
xmlns="http://www.w3.org/1999/xhtml<https://urldefense.com/v3/__http:/www.w3.
org/1999/xhtml__;!!A4F2R9G_pg!Jhl_IDRYqlo2VzhBevEPT2OWcoGcLIPmsruLOTbumPfCYoJ
_cCkeVydWWU_RjqAl8DdrvKRONX00fVk$>">
  <head>
    <title>Equations</title>
  </head>
  <body>
    <math
xmlns="http://www.w3.org/1998/Math/MathML<https://urldefense.com/v3/__http:/w
ww.w3.org/1998/Math/MathML__;!!A4F2R9G_pg!Jhl_IDRYqlo2VzhBevEPT2OWcoGcLIPmsru
LOTbumPfCYoJ_cCkeVydWWU_RjqAl8DdrvKROJrOkqso$>">
      <mrow>
        <mrow>
          <mspace/>
        </mrow>
      </mrow>
    </math>
  </body>
</html>


In retrospect, my mistakes were:

1. Thinking that "xpath-default-namespace" affected new element creation too.
2. Not realizing that the <mspace> created by my template was *not* in the
MathML namespace.

Many thanks!!

 - Chris



--
...Wendell Piez... ...wendell -at- nist -dot- gov...
...wendellpiez.com... ...pellucidliterature.org... ...pausepress.org...
...github.com/wendellpiez.<https://urldefense.com/v3/__http:/github.com/wende
llpiez.__;!!A4F2R9G_pg!Jhl_IDRYqlo2VzhBevEPT2OWcoGcLIPmsruLOTbumPfCYoJ_cCkeVy
dWWU_RjqAl8DdrvKRObEgyriU$>.. ...gitlab.coko.foundation/wendell...
XSL-List info and
archive<https://urldefense.com/v3/__http:/www.mulberrytech.com/xsl/xsl-list__
;!!A4F2R9G_pg!Jhl_IDRYqlo2VzhBevEPT2OWcoGcLIPmsruLOTbumPfCYoJ_cCkeVydWWU_RjqA
l8DdrvKROeie5NT4$>
EasyUnsubscribe<https://urldefense.com/v3/__http:/lists.mulberrytech.com/unsu
b/xsl-list/3380743__;!!A4F2R9G_pg!Jhl_IDRYqlo2VzhBevEPT2OWcoGcLIPmsruLOTbumPf
CYoJ_cCkeVydWWU_RjqAl8DdrvKROQ4jx_Bc$> (by email<>)

Current Thread