2017-10-13 115 views
0

输入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> 

它不反映正确的输出。你能帮助我们解决这个问题吗?

回答

0

您可以使用此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> 
+0

感谢您的答复Rupesh。它工作正常。 – Sumathi

+0

我们在下面提到的上面提到的xslt工作不正常的情况。 <图1D = “c001_f002” 计数器= “是”> <图形位置= “中心” fileref = “图像/ 9781626237896_c001_f002a.jpg”/> <图形位置= “中心” fileref =”图片/ 9781626237896_c001_f002b.jpg“/> 图1-2瘢痕疙瘩。 在这种情况下,“legend”元素应该移动到“figure”下面的“subfigure”元素的上方。但是当使用上面提到的xslt时,图例出现在两个“子图”元素之间。 – Sumathi

+0

您能指导我们,在这种情况下如何编写代码。 – Sumathi