2014-01-27 92 views
0

在輸入xml中,每個段落中的每個段落都沒有腳註。我想設置一個腳註可用的鏈接,我需要將所有腳註移動到本章末尾的html中。腳註替換到本章末尾

爲了供大家參考,我正在粘貼我的輸入文件。

<section level="1"> 
<heading class="hdgautonum1" level="1"><inline style="\-ilx-tab-stops: left blank 0tw; "><gentext type="headingnumberstring">1 </gentext>Introduction</inline></heading> 
<par class="para"><inline class="glossaryrefmain">ITIL</inline> is part of a suite of best-practice publications for <inline class="glossaryrefmain">IT service management</inline> (ITSM).<inline class="footnote&#160;reference"><footnote> 
<par class="footnote&#160;text"> ITSM and other concepts from this chapter are described in more detail in Chapter 2.</par></footnote></inline> ITIL provides guidance to <inline class="glossaryrefmain">service provider</inline>s on the provision of quality</par> 
</section> 

任何想法?

+0

請出示你迄今爲止嘗試過 - 那麼,就比較容易告訴你,你出錯。你使用的是什麼版本的XSLT? –

+0

這與構建索引基本相同,只是(a)要在「被索引」的位置插入腳註標記,(b)在「文本」正文之後出現「索引」的第二遍而不是之前。查看[XSL常見問題解答](http://www.dpawson.co.uk/xsl/sect2/sect21.html)網站上的索引示例,該網站收集了常見問題的過去解決方案;我還沒有找到腳註的答案,但有索引的例子可以改編。 – keshlam

+0

另請參閱https://stackoverflow.com/questions/15269554/with-xslt-how-can-i-process-normally-but-hold-some-nodes-until-the-end-and-the?rq=1 – keshlam

回答

1

試試這個模板:當適用於您的輸入XML

<?xml version="1.0" encoding="UTF-8"?> 
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
    version="1.0"> 

    <!-- copies all nodes --> 
    <xsl:template match="@*|node()"> 
     <xsl:copy> 
      <xsl:apply-templates select="@*|node()"/> 
     </xsl:copy> 
    </xsl:template> 

    <!-- generate footnote link --> 
    <xsl:template match="footnote"> 
     <xref> 
      <xsl:attribute name="rid">fn<xsl:number level="any" format="1"/></xsl:attribute> 
      <xsl:number level="any" format="1"/> 
     </xref> 
    </xsl:template> 

    <!-- removes container footnote&#160;reference, or you can retain them, just remove the comment marks o xsl:copy --> 
    <xsl:template match="inline[contains(@class, 'footnote')]"> 
     <!--<xsl:copy> 
      <xsl:copy-of select="@*"/>--> 
     <xsl:apply-templates/> 
     <!--</xsl:copy>--> 
    </xsl:template> 

    <!-- moves all footnotes at the end --> 
    <xsl:template match="section"> 
     <root> 
      <xsl:copy> 
       <xsl:copy-of select="@*"/> 
       <xsl:apply-templates/> 
      </xsl:copy> 
      <footnote-group> 
       <xsl:apply-templates select="//footnote" mode="group"/> 
      </footnote-group> 
     </root> 
    </xsl:template> 

    <!-- template to fix footnotes, in a different mode --> 
    <xsl:template match="footnote" mode="group"> 
     <footnote> 
      <xsl:attribute name="id">fn<xsl:number level="any" format="1"/></xsl:attribute> 
      <label><xsl:number level="any" format="1"/></label> 
      <xsl:apply-templates/> 
     </footnote> 
    </xsl:template> 

</xsl:stylesheet> 

,它輸出:

<?xml version="1.0" encoding="utf-8"?> 
<root> 
    <section level="1"> 
     <heading class="hdgautonum1" level="1"> 
      <inline style="\-ilx-tab-stops: left blank 0tw; "><gentext type="headingnumberstring">1 
       </gentext>Introduction</inline> 
     </heading> 
     <par class="para"><inline class="glossaryrefmain">ITIL</inline> is part of a suite of 
      best-practice publications for <inline class="glossaryrefmain">IT service 
       management</inline> (ITSM).<xref rid="fn1">1</xref> ITIL provides guidance to 
       <inline class="glossaryrefmain">service provider</inline>s on the provision of 
      quality</par> 
    </section> 
    <footnote-group> 
     <footnote id="fn1"> 
      <label>1</label> 
      <par class="footnote text"> ITSM and other concepts from this chapter are described in 
       more detail in Chapter 2.</par> 
     </footnote> 
    </footnote-group> 
</root>