0

This is my input:

                         <mathml>
                            <m:math xmlns:m="http://www.w3.org/1998/Math/MathML">
                                <m:mrow>
                                    <m:mtext>SL depreciation expense</m:mtext>
                                    <m:mo>=</m:mo>
                                    <m:mfrac>
                                        <m:mrow>
                                            <m:mtext>cost−residual value</m:mtext>
                                        </m:mrow>
                                        <m:mrow>
                                            <m:mtext>useful life</m:mtext>
                                        </m:mrow>
                                    </m:mfrac>
                                </m:mrow>
                            </m:math>
                        </mathml>

This is expected output

            <math xmlns="http://www.w3.org/1998/Math/MathML">
            <mrow>
                <mtext>SL depreciation expense</mtext>
                <mo>=</mo>
                <mfrac>
                    <mrow>
                        <mtext>cost−residual value</mtext>
                    </mrow>
                    <mrow>
                        <mtext>useful life</mtext>
                    </mrow>
                </mfrac>
            </mrow>
        </math>

I want to copy all the children of mathml node without the m: prefix namespace without having to create a template for each element. Can you suggest any solution for this?

2 Answers2

0

You can use the following snippet to copy what is inside math

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

To remove namespaces, you should create your element using xsl:element have a look to this answer that woud help you doing this.

Muhammad Soliman
  • 21,644
  • 6
  • 109
  • 75
0

Try having:

<xsl:template match="m:*">
    <xsl:element name="{local-name()}" namespace="http://www.w3.org/1998/Math/MathML">
        <xsl:apply-templates/>
    </xsl:element>
</xsl:template>

See http://xsltfiddle.liberty-development.net/6qVRKvZ.

Joel M. Lamsen
  • 7,143
  • 1
  • 12
  • 14