开发者

XSL copy-of copies outer node

开发者 https://www.devze.com 2023-04-05 07:03 出处:网络
I\'m trying to process the following XML snippet: <inlineequation><mml:math> <!-- eqn: [-1,1]:-->

I'm trying to process the following XML snippet:

        <inlineequation><mml:math>
            <!-- eqn: [-1,1]:-->
            <mml:mfenced open="[" close="]">
                <mml:mn>-1</mml:mn>
                <mml:mn>1</mml:mn>
            </mml:mfenced>
        </mml:math></inlineequation>

The best result I got is to copy the entire markup, by using the copy-of function:

<xsl:template match="para/inlineequation">
    <xsl:copy-of select="."/>
</xsl:template>

However, the transformed XML will have also the inlineequation node, while I want to strip it out. Indeed the correct output shall be:

        <mml:math><mml:mfenced open="[" close="]">
            <mml:mn>-1</mml:mn&g开发者_如何学运维t;
            <mml:mn>1</mml:mn>
        </mml:mfenced></mml:math>

How to achieve the result above? The result I'm getting now is:

        <inlineequation><mml:math>
        <mml:mfenced open="[" close="]">
            <mml:mn>-1</mml:mn>
            <mml:mn>1</mml:mn>
        </mml:mfenced>
        </mml:math></inlineequation>


Just use:

<xsl:template match="para/inlineequation">
    <xsl:copy-of select="*"/>
</xsl:template>

or, if you have correctly declared the namespace:

<xsl:template match="para/inlineequation">
    <xsl:copy-of select="mml:math"/>
</xsl:template>

or

<xsl:template match="mml:math">
    <xsl:copy-of select="."/>
</xsl:template>
0

精彩评论

暂无评论...
验证码 换一张
取 消