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: Fri, 6 Nov 2020 01:12:34 -0000
Hi Wendell, all,

My bxpath-default-namespace" solution worked when I modified only MathML
content, but it failed when I tried to modify both MathML and HTML content.
:(

Your note that XSLT documents themselves follow XML namespace rules got me
thinkingb& and I also came across the November 2013 solution from Ian Roberts
here, suggesting pertinent default namespaces on the <xsl:template> element
themselves:

https://stackoverflow.com/questions/20090833/best-solution-dealing-with-defau
lt-namespaces-in-xml-and-xslt

and that seemed like a perfect and intuitive solution! But I canbt get it to
work.

Given this input document (HTML top level, MathML within):


<html>
  <head>
    <title>Equations</title>
  </head>
  <body>
    <p>
      <math xmlns="http://www.w3.org/1998/Math/MathML";>
        <mi>m</mi>
      </math>
    </p>
  </body>
</html>


and this stylesheet:


<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
  xmlns:xs="http://www.w3.org/2001/XMLSchema";
  exclude-result-prefixes="xs"
  version="2.0">

  <!-- baseline identity transform -->
  <xsl:template match="@*|node()">
    <xsl:copy>
      <xsl:apply-templates select="@*|node()"/>
    </xsl:copy>
  </xsl:template>

  <xsl:template match="p">
    <div>
      <xsl:copy-of select="."/>
    </div>
  </xsl:template>

  <xsl:template xmlns="http://www.w3.org/1998/Math/MathML"; match="mi">
    <mrow>
      <xsl:copy-of select="."/>
    </mrow>
  </xsl:template>

</xsl:stylesheet>


the template for HTML <p> fires, but the template for MathML <mi> does not.
What am I doing wrong? I tried other solutions and I havenbt found anything
to allow me to modify content in both namespace domains.

Thanks!!


  *   Chris


From: Wendell Piez wapiez@xxxxxxxxxxxxxxx<mailto:wapiez@xxxxxxxxxxxxxxx>
<xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx<mailto:xsl-list-service@xxxxxxxxxxxx
rytech.com>>
Sent: Wednesday, November 4, 2020 11:12 AM
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx<mailto: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

Current Thread