I'm trying to transform a document that has math
elements with namespace xmlns="http://www.w3.org/1998/Math/MathML"
, transformation noT working if it has xmlns
but it works if xmlns
removed from the element I don't know what I'm missing here.
I example with and without xmlns.
To refer code instantly check this link https://xsltfiddle.liberty-development.net/bET2rXa/1
Original Doc:
<?xml version="1.0" encoding="utf-8" ?>
<html>
<head>Test Document</head>
<body>
<article attr1="1" attr2="2">
<math xmlns="http://www.w3.org/1998/Math/MathML"><msup><mrow><mi>a</mi></mrow><mrow><mn>2</mn></mrow></msup><mo>+</mo><msup><mrow><mi>b</mi></mrow><mrow><mn>2</mn></mrow></msup><mo> = </mo><msup><mrow><mi>c</mi></mrow><mrow><mn>2</mn></mrow></msup></math>
<math><msup><mrow><mi>a</mi></mrow><mrow><mn>2</mn></mrow></msup><mo>+</mo><msup><mrow><mi>b</mi></mrow><mrow><mn>2</mn></mrow></msup><mo> = </mo><msup><mrow><mi>c</mi></mrow><mrow><mn>2</mn></mrow></msup></math>
</article>
</body>
</html>
Actual Transformation Output:
<html>
<head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8">Test Document</head>
<body>
<article attr1="1" attr2="2">
a2+b2 = c2
<math><msup><mrow><mi>a</mi></mrow><mrow><mn>2</mn></mrow></msup><mo>+</mo><msup><mrow><mi>b</mi></mrow><mrow><mn>2</mn></mrow></msup><mo> = </mo><msup><mrow><mi>c</mi></mrow><mrow><mn>2</mn></mrow></msup></math>
</article>
</body>
</html>
XSLT:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns="http://www.w3.org/1999/xhtml" version="3.0">
<xsl:mode on-no-match="shallow-copy"/>
<xsl:output method="html" indent="no" html-version="5"/>
<xsl:template match="*">
<xsl:apply-templates />
</xsl:template>
<xsl:template match="@*">
<xsl:apply-templates />
</xsl:template>
<xsl:template match="node() | @*" mode="copy-after-all">
<xsl:copy>
<xsl:apply-templates select="@*"/>
<xsl:apply-templates/>
</xsl:copy>
</xsl:template>
<xsl:template match="html | head | body | article | article/@*">
<xsl:apply-templates select="." mode="copy-after-all"/>
</xsl:template>
<xsl:template match="math | math//* | math//@*">
<xsl:apply-templates select="." mode="copy-after-all"/>
</xsl:template>
</xsl:stylesheet>