我希望删除 xml 中的几个节点并添加新节点。让我用下面的 xml 来说明:
<resprocessing>
<respcondition title="Correct" continue="No">
<conditionvar>
<varequal respident="Response_0">
<nhm_blank_name>Answer:</nhm_blank_name>
<nhm_numerator>14</nhm_numerator>
<nhm_denominator>25</nhm_denominator>
<nhm_allow_multiples>No</nhm_allow_multiples>
</varequal>
</conditionvar>
</respcondition>
</resprocessing>
我想删除节点<nhm_numerator>
并在下面<nhm_denominator>
插入一个新节点(<nhm_blank_value>
),<varequal>
同时保留其他两个节点 <nhm_blank_name>
<nhm_allow_multiples>
新节点的值如下:
<nhm_blank_value>
<math xmlns="http://www.w3.org/1998/Math/MathML">
<mfrac>
<mn>14</mn>
<mn>25</mn>
</mfrac>
</math>
</nhm_blank_value>
我使用以下 XSLT 成功删除了上述节点。但我无法添加新节点。请告诉我哪里出错了
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output omit-xml-declaration="yes" indent="yes"/>
<xsl:param name="mathml">
<nhm_blank_value>
<math xmlns="http://www.w3.org/1998/Math/MathML">
<mfrac>
<mn>14</mn>
<mn>25</mn>
</mfrac>
</math>
</nhm_blank_value>
</xsl:param>
<!-- copy the xml as it is -->
<xsl:template match="node()|@*">
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
</xsl:copy>
</xsl:template>
<!-- deleting nodes numerator and denominator -->
<xsl:template match="questestinterop/item/resprocessing/respcondition/conditionvar/varequal/nhm_denominator" />
<xsl:template match="questestinterop/item/resprocessing/respcondition/conditionvar/varequal/nhm_numerator" />
<!-- adding mathml node -->
<xsl:template match="questestinterop/item/resprocessing/respcondition/conditionvar">
<xsl:value-of select="varequal">
<xsl:with-param name="mathml"/>
</xsl:value-of>
</xsl:template>
</xsl:stylesheet>