首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Xslt将脚注标记移动到父节点的末尾。

Xslt将脚注标记移动到父节点的末尾。
EN

Stack Overflow用户
提问于 2015-07-03 05:30:37
回答 1查看 581关注 0票数 0

这是我的xml文件

代码语言:javascript
复制
<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,我用下面的xsl将它转换成html

代码语言:javascript
复制
 <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我得到了如下所示的输出

代码语言:javascript
复制
 <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=“脚注”都出现在章节标签的末尾,谁能帮我吗?

我想把它放在下面

代码语言:javascript
复制
<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>
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-07-03 16:56:59

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

代码语言:javascript
复制
<?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>不是在notes模式下显式处理的;因此,我们只得到它们各自的文本,而没有周围的<p>

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/31199134

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档