移动子元素
问题描述:
输入XML就像是为移动子元素
<figure id="f1_1">
<subfigure>
<graphic position="center" fileref="images/9781626233614_c001_f001.jpg"/>
<legend><para>Reeve’s prosthesis. (Reproduced with permission from Reeves B, Jobbins B, Dowson D, Wright V. A Total Shoulder Endo-Prosthesis.</para></legend>
</subfigure>
</figure>
输出应该是
<figure id="f1_1">
<legend><para>Reeve’s prosthesis. (Reproduced with permission from Reeves B, Jobbins B, Dowson D, Wright V. A Total Shoulder Endo-Prosthesis.</para></legend>
<subfigure>
<graphic position="center" fileref="images/9781626233614_c001_f001.jpg"/>
</subfigure>
</figure>
我已经写了XSLT等作为,
<xsl:template match="subfigure">
<xsl:choose>
<xsl:when test="following-sibling::legend">
<xsl:variable name="a1" select="following-sibling::legend"/>
<xsl:copy-of select="$a1"/>
<xsl:copy>
<xsl:apply-templates select="node() | @*"/>
</xsl:copy>
</xsl:when>
<xsl:otherwise>
<xsl:copy>
<xsl:apply-templates select="node() | @*"/>
</xsl:copy>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
它不反映正确的输出。你能帮助我们解决这个问题吗?
答
您可以使用此XSLT 2.0:
<xsl:template match="subfigure">
<xsl:copy-of select="legend"/>
<xsl:copy>
<xsl:apply-templates select="node() except legend"/>
</xsl:copy>
</xsl:template>
感谢您的答复Rupesh。它工作正常。 – Sumathi
我们在下面提到的上面提到的xslt工作不正常的情况。 在这种情况下,“legend”元素应该移动到“figure”下面的“subfigure”元素的上方。但是当使用上面提到的xslt时,图例出现在两个“子图”元素之间。 –
Sumathi
您能指导我们,在这种情况下如何编写代码。 – Sumathi