带有章节和脚注的XML文档

时间:2015-07-10 20:08:25

标签: xml xslt

我是XML编程的新手。我创建了一个XML文件来保存我的数据和一个xsl文件来转换它。它创建一个html文件,这是一个简单的文档,包含标题,章节,段落和脚注。我不希望所有脚注出现在每章之后,而只是该章的脚注。我无法弄清楚该怎么做,请帮忙。 这是XSL:

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet  version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Form">
                <xsl:output method="html" version="3.0" omit-xml-declaration="yes" indent="no" />
                <xsl:param name="Notes" select="'true'" />
                    <xsl:template match="/Collection">
                        <html>
                            <head>
                                        <style>
                                                a {text-decoration:none;}
                                                a.tooltip {outline:none; }              
                                                a.tooltip strong {line-height:30px;} 
                                                a.tooltip:hover {text-decoration:bold;} 
                                                a.tooltip span { z-index:10;display:none; padding:14px 20px; margin-top:-30px; margin-left:28px; width:300px; line-height:16px; } 
                                                a.tooltip:hover span{ display:inline; position:absolute; color:#111; border:1px solid #DCA; background:#fffAF0;} 
                                                .callout {z-index:20;position:absolute;top:30px;border:0;left:-12px;} 
                                                a.tooltip span { border-radius:4px; box-shadow: 5px 5px 8px #CCC; }                             
                                            .Seriestitle {font-family: Arial,Univers,sans-serif; font-size: 24pt;text-align: center; }
                                            .ChapterTitle {font-family: Arial,Univers,sans-serif; font-size: 14pt ;text-align: left;}
                                            .BookTitle {font-family: Arial,Univers,sans-serif; font-size: 14pt ;text-align: left;}
                                        </style>    

                            </head>
                            <body>

                                <xsl:apply-templates select="Series"/>
                            </body>
                        </html>
                    </xsl:template>

                <xsl:template match="Series">
                                <div class="Seriestitle"><xsl:value-of select="Title"/></div>
                                <xsl:apply-templates select="SeriesIntroduction"/>
                                <xsl:apply-templates select="Book"/>
                </xsl:template>     


                <xsl:template match="SeriesIntroduction">
                                <p><xsl:apply-templates select="IntroContent"/></p>
                </xsl:template>

                <xsl:template match="Book">
                                <p class="BookTitle"><xsl:value-of select="Title"/>
</p>
                                <xsl:apply-templates select="Introduction"/>
                                <xsl:apply-templates select="Chapter"/>

                </xsl:template> 

                <xsl:template match="Introduction">
                                <p><b><xsl:value-of select="Title"/></b></p>
                                <xsl:apply-templates select="IntroContent"/>
                </xsl:template>

                <xsl:template match="Chapter">
                                <p  class="ChapterTitle"><xsl:value-of select="@chapterTitle"/>: <xsl:value-of select="ChapterTitle"/></p>
                                <xsl:apply-templates select="ChapterContent"/>

                </xsl:template>

                <xsl:template match="ChapterContent">
                                <p><xsl:apply-templates/></p>
                                <xsl:apply-templates select="//footnote" mode="fulltext"  />

                </xsl:template>

                <xsl:template match="footnote">
                                 <a>
                                                <xsl:attribute name="class">
                                                               <xsl:text>tooltip</xsl:text>
                                                  </xsl:attribute>                               
                                                <xsl:attribute name="name">
                                                               <xsl:text>footnoteref</xsl:text><xsl:number level="single" count="footnote" format="1"/>
                                                  </xsl:attribute>
                                                  <xsl:attribute name="href">
                                                                <xsl:text>#footnote</xsl:text><xsl:number level="single" count="footnote" format="1"/>
                                                </xsl:attribute>
                                              <sup><xsl:number level="single" count="footnote" format="1"/></sup>
                                              <span><xsl:value-of select="@notetext"/></span>
                                 </a>
                </xsl:template> 

                <xsl:template match="footnote" mode="fulltext">
                                <p>
                                                <a>
                                                                 <xsl:attribute name="name">
                                                                                <xsl:text>footnote</xsl:text><xsl:number level="single" count="footnote" format="1"/>
                                                                  </xsl:attribute>
                                                                <xsl:attribute name="href">
                                                                                    <xsl:text>#footnoteref</xsl:text><xsl:number level="single" count="footnote" format="1"/>
                                                                </xsl:attribute>
                                                                <sup><xsl:number level="single" count="footnote" format="1"/>
</sup>
                                                 </a>
                                                <xsl:value-of select="@notetext"/>
                                </p>
                </xsl:template>             
</xsl:stylesheet>

这是XML:

<?xml version="1.0" encoding="utf-8"?>
<!-- New document created with EditiX at Fri Mar 27 12:23:38 EDT 2015 -->
<?xml-stylesheet type="text/xsl" href="CrossReferenceCollection.xsl"?>
<Collection>
  <Series>
    <Title>The Apostolic Fathers, Justin Martyr, Irenaeus</Title>
    <SeriesIntroduction>
      <IntroContent>
        <para>
          <word>Text removed for brevity and clarity.</word>
          <word>Text removed for brevity and clarity.</word>
          <word>Text removed for brevity and clarity.</word>
        </para>
      </IntroContent>
      <IntroNotes></IntroNotes>
    </SeriesIntroduction>
    <Book BookNumber="1">
      <Title>First Epistle of Clement to the Corinthians</Title>
      <Introduction>
        <Title>Introductory Note to the First Epistle of Clement to the Corinthians</Title>
        <IntroContent>
          <para>
            <word>Text removed for brevity and clarity.</word>
          </para>
          <para>
            <word>Text removed for brevity and clarity.</word>
          </para>
          <para>
            <word>Text removed for brevity and clarity.</word>
          </para>
          <para>
            <word>Text removed for brevity and clarity.</word>
          </para>
          <para>
            <word>Text removed for brevity and clarity.</word>
          </para>
          <para>
            <word>Text removed for brevity and clarity.</word>
          </para>
          <para>
            <word>Text removed for brevity and clarity.</word>
          </para>
          <para>
            <word>Text removed for brevity and clarity.</word>
          </para>
          <para>
            <word>Text removed for brevity and clarity.</word>
          </para>
        </IntroContent>
        <IntroNotes></IntroNotes>
      </Introduction>
      <Chapter chapterTitle="CHAPTER 1">
        <ChapterTitle>The salutation. Praise of the Corinthians before the breaking forth of schism among them
</ChapterTitle>
        <ChapterContent>
          <para>
            <word>Text removed for brevity and clarity.</word>
            <word>Owing, dear brethren, to the sudden and successive calamitous events which have happened to ourselves, we feel that we have been somewhat tardy in turning our attention to the points respecting which you consulted us; </word>
            <footnote label="1" notetext="Note the fact that the Corinthians asked this of their brethren,  the personal friends of their apostle St. Paul. Clement's own name does not appear in this Epistle."></footnote>
            <word> and especially to that shameful and detestable sedition, utterly abhorrent to the elect of God, which a few rash and self-confident persons have kindled to such a pitch of frenzy, that your venerable and illustrious name, worthy to be universally loved, has suffered grievous injury. </word>
            <footnote label="2" notetext="Literally, 'is greatly blasphemed.'"></footnote>
            <word> For who ever dwelt even for a short time among you, and did not find your faith to be as fruitful of virtue as it was firmly established? </word>
            <footnote label="3" notetext="Literally, 'did not prove your all-virtuous and firm faith.'"></footnote>
            <word> Who did not admire the sobriety and moderation of your godliness in Christ? Who did not proclaim the magnificence of your habitual hospitality? And who did not rejoice over your perfect and well-grounded knowledge? For ye did all things without respect of persons, and walked in the commandments of God, being obedient to those who had the rule over you, and giving all fitting honour to the presbyters among you. Ye enjoined young men to be of a sober and serious mind; ye instructed your wives to do all things with a blameless, becoming, and pure conscience, loving their husbands as in duty bound; and ye taught them that, living in the rule of obedience, they should manage their household affairs becomingly, and be in every respect marked by discretion.</word>
          </para>
        </ChapterContent>
        <Notes />
      </Chapter>
      <Chapter chapterTitle="CHAPTER 2">
        <ChapterTitle>Praise of the Corinthians continued.</ChapterTitle>
        <ChapterContent>
          <para>
            <word>Moreover, ye were all distinguished by humility, and were in no respect puffed up with pride, but yielded obedience rather than extorted it,</word>
            <footnote label="1" notetext="Ephesians 5:21" Crossref="Ephesians 5:21"></footnote>
            <footnote label="2" notetext="1 Peter 5:5" Crossref="1 Peter 5:5"></footnote>
            <word> and were more willing to give than to receive.</word>
            <footnote label="3" notetext="Acts 20:35"></footnote>
            <word> Content with the   provision which God had made for you, and carefully attending to His words, ye were inwardly filled</word>
            <footnote label="4" notetext="Literally, 'ye embraced it in your bowels.' [Concerning the complaints of Photius (ninth century) against Clement, see Bull's Defensio Fidei Nicænæ, Works, vol. v. p. 132.]"></footnote>
            <word> with His doctrine, and His sufferings were before your eyes. Thus a profound and abundant peace was given to you all, and ye had an insatiable desire for doing good, while a full outpouring of the Holy Spirit was upon you all. Full of   holy designs, ye did, with true earnestness of mind and a godly confidence, stretch forth your hands to God Almighty, beseeching Him to be merciful unto you, if ye had been guilty of any involuntary transgression. Day and night ye were anxious for the whole brotherhood,</word>
            <footnote label="5" notetext="1 Peter 2:17"></footnote>
            <word> that the number of God's elect might be saved with mercy and a good conscience.</word>
            <footnote label="6" notetext="So, in the ms., but many have suspected that the text is here corrupt. Perhaps the best emendation is that which substitutes sunaistheseos, 'compassion,' for suneideseos, 'conscience.'"></footnote>
            <word> Ye were sincere and uncorrupted, and forgetful of injuries between one another. Every kind of faction and schism was abominable in your sight. Ye mourned over the transgressions of your neighbours: their deficiencies you deemed your own. Ye never grudged any act of kindness, being "ready to every good work."</word>
            <footnote label="7" notetext="Titus 3:1"></footnote>
            <word> Adorned by a thoroughly virtuous and religious life, ye did all things in the fear of God. The commandments and ordinances of the Lord were written upon the tablets of your hearts.</word>
            <footnote label="8" notetext="Proverbs 7:3"></footnote>
            <word></word>
          </para>
        </ChapterContent>
        <Notes />
      </Chapter>
    </Book>
  </Series>
</Collection>

1 个答案:

答案 0 :(得分:2)

而不是:

<xsl:apply-templates select="//footnote" mode="fulltext"  />

尝试:

<xsl:apply-templates select=".//footnote" mode="fulltext"  />

或(最好,如果层次结构一致):

<xsl:apply-templates select="para/footnote" mode="fulltext"  />

否则您从根节点开始选择整个文档中的全部脚注。