Xslt将脚注标记移动到父级的末尾

时间:2015-07-03 05:30:38

标签: html xml xslt

这是我的xml文件

<chapter>
<section>
    <info>
    <title>footnote</title>
    </info>
    <para>welcome to xml footnote</para>
    <para>something</para>
    <para> something.......
    <footnote role="end-ch-note" xml:id="b-9781472580740-0000409" label="1">
    <para xml:id="b-9781472580740-0001874">
     somrthing......</para>
     </footnote>something.....
     </para>         
     <para> something.......
    <footnote role="end-ch-note" xml:id="b-9781472580740-0000410" label="2">
    <para xml:id="b-9781472580740-0001875">
     somrthing......</para>
     </footnote>something.....
     </para>
</section>
</chapter>

我希望所有脚注标记都在“插入项目标记”下面。

这是我的xsl我将其转换为html,后面跟着xsl

 <xsl:template match="book/chapter">
    <div class="pagebreak">
        <xsl:attribute name="id">
            <xsl:value-of select="@xml:id"/>
        </xsl:attribute>
        <xsl:apply-templates/>
    </div>
</xsl:template>

<xsl:template match="chapter[@label]">          
    <div class="pagebreak" id="CT-{@label}">
        <p class="ChapNumber">
        <xsl:value-of select="@label"/>             
        </p>
        <div class="chapterinfo"><xsl:apply-templates/></div>
        </div>
</xsl:template>

 <xsl:template match="chapter/info/title">
    <p class="ChapTitle">
        <xsl:apply-templates/>
    </p>
</xsl:template>         
     <xsl:template match="footnote[@label]">
    <a>
        <xsl:attribute name="href">
            <xsl:text>#fn</xsl:text>
            <xsl:value-of select="../@xml:id"/>
        </xsl:attribute>
        <sup>
            <xsl:value-of select="@label"/>
        </sup>
    </a>
    <div class="footnote">
        <xsl:attribute name="id">
            <xsl:text>fn</xsl:text>
            <xsl:value-of select="../@xml:id"/>
        </xsl:attribute>            
        <xsl:apply-templates/>
    </div>
 </xsl:template>

我通过使用xsl

得出如下所示
 <div class="pagebreak" id="CT-2">
 <p class="ChapNumber">2</p>
 <div class="chapterinfo">
 <p class="ChapTitle">International Tax Cooperation and Implications of       Globalization</p>
 <a href="#fnb-9781472580740-0000409">
              <sup>1</sup>
           </a>
  <div class="footnote" id="fnb-9781472580740-0000409">
  <p class="Text">A prior version of this chapter was published     by the Friedrich Ebert Stiftung in its International Policy Analysis series. It draws from my previous work on the subject, which has been supported by the Ford Foundation.</p>
  </div>
  <div class="textindent">something...............</div>
  <div calss="text">something.............</div>
  <a href="#fnb-9781472580740-0000410">
  <sup>2</sup>
  </a>
  <div class="footnote" id="fnb-9781472580740-0000410">
  <p class="Text">A prior version of this chapter was published by the Friedrich Ebert Stiftung in its International Policy Analysis series. It draws from my previous work on the subject, which has been supported by the Ford Foundation.</p>
  </div>
  </div>
  </div>

我希望所有div class =“footnote”都出现在chapter标签的末尾 任何人都可以帮助我

我想要像下面那样放

<div class="chapter">
<div class="section">       
    <div class="title">footnote</div>       
    <p class="textindent">welcome to xml footnote</p>
    <p class="text">something</p>
    <p class="text">something.......
        <a href="#fnb-b-9781472580740-0000409">
              <sup>1</sup>
           </a>            
            something.....
     </p>        
     <p class="text"> something.......
    <a href="#fnb-b-9781472580740-0000410">
              <sup>1</sup>
           </a>
           something.....
     </p>
</div>
<div class="notes">
<div class="footnote" id="fnb-9781472580740-0000409">
            <p class="Text">something.......</p>
           </div>
<div class="footnote" id="fnb-9781472580740-0000410">
            <p class="Text">something.......</p>
           </div>
           </div>
           </div>

1 个答案:

答案 0 :(得分:0)

以下样式表根据您的脚注要求生成所需的输出:

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

    <xsl:output method="html" indent="no"/>

    <xsl:template match="chapter">
        <div class="chapter">
            <xsl:apply-templates/>
            <div class="notes">
                <xsl:apply-templates select=".//footnote[@label]" mode="notes"/>
            </div>
        </div>
    </xsl:template>

    <xsl:template match="section">
        <div class="section">
            <xsl:apply-templates/>
        </div>
    </xsl:template>

    <xsl:template match="title">
        <div class="title">
            <xsl:apply-templates/>
        </div>
    </xsl:template>

    <xsl:template match="para">
        <p>
            <xsl:apply-templates/>
        </p>
    </xsl:template>

    <xsl:template match="footnote[@label]">
        <a href="{concat('#fn',@xml:id)}" id="{@xml:id}">
            <sup><xsl:value-of select="@label"/></sup>
        </a>
    </xsl:template>

    <xsl:template match="footnote[@label]" mode="notes">
        <div class="footnote" id="{concat('fn',@xml:id)}">
            <a href="{concat('#',@xml:id)}">
                <sup>
                    <xsl:value-of select="@label"/>
                </sup>
            </a>
            <xsl:apply-templates mode="notes"/>
        </div>
    </xsl:template>

</xsl:stylesheet>

应该提到三点:

a)在正常模式下,<footnote>放置其标签号,链接到笔记部分,

b)脚注在notes结束时以<chapter>模式第二次处理。在此模式下,他们的文本被放入<div class="notes">,而标签编号则链接回正常文本中的调用脚注。

c)<para>&#39}未在notes模式下明确处理;因此,我们只获取各自的文字,而不是<p>