2017-10-13 114 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