XSL copy-of copies outer node
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>
精彩评论