Exercise 9: Change footnotes

Change footnote behavior

Introduction:

For the final exercise we are going to move from search results and forms to object display. TEI documents have many different note types. In the default stylesheets, footnote references trigger a pop-up window, while endnote references scroll to the endnote section and highlight the note selected. Here we are going to dynamically gather all of a chapter’s footnotes together like endnotes and enable the endnote-style scrolling/highlight behavior for them.

Demonstration:

Steps:

  1. Take a look at how footnotes behave in this document:

    http://localhost:8080/xtf/view?docId=tei/ft2g5004sk/ft2g5004sk.xml;chunk.id=d0e31

  2. Now open:

    %XTF_HOME%\style\dynaXML\docFormatter\tei\component.xsl

    We are going to change the URL for footnote reference links so that they display the same behavior as those for endnote references.

  3. In the template that matches ‘ref’:

    <xsl:template match=”*[local-name()=’ref’]”>

    find this comment:

    <!– footnote refs –>

    and comment out the xsl:when for @type=’fnoteref’. Then change the xsl:when above it so that it also applies to this type:

    <xsl:when test=”@type=’noteref’ or @type=’endnote’ or @type=’fnoteref'”>

  4. Now open:

    %XTF_HOME%\style\dynaXML\docFormatter\tei\structure.xsl

    Here we are going to create the new note section at the end of chapters and enable scrolling and highlighting.

  5. Look for the template that matches all “div” elements:

    <!—all div elements –>
    <xsl:template match=”*[matches(local-name(),’^div’)]”>

  6. Now create a place for the notes at the end of each chapter, by adding an xsl:if that tests for @type=’chapter’ at the bottom of this template. Within it put an <h3> with whatever title you would like to use, and open an ordered list:

    <xsl:if test=”@type=’chapter'”>
    <h3>Footnotes</h3>
    <ol>

    </ol>
    </h3>
    </xsl:if>
    

  7. Within this list, use an xsl:foreach to grab all of the footnotes in the chapter and create the ordered list from them:

    <xsl:for-each select=”.//*[local-name()=’note’][@type=’footnote’]”>
    <li>
    <xsl:apply-templates/>
    </li>
    </xsl:for-each>

  8. To enable scrolling and hit highlighting, you will have to add an <xsl:choose> that determines whether the id attribute of the note matches the value of $anchor.id in the URL:

    <xsl:choose>
    <xsl:when test=”$anchor.id=@*[local-name()=’id’]”>
    <a name=”X”></a>
    <div>
    <xsl:apply-templates/>
    </div>
    </xsl:when>
    <xsl:otherwise>
    <div>
    <xsl:apply-templates/>
    </div>
    </xsl:otherwise>
    </xsl:choose>
    

  9. Now try the URL above again and see if your endnote section has appeared, and whether the link behavior has changed.

    Complete Solution:

    <xsl:if test=”@type=’chapter'”>
    <h3>Footnotes</h3>
    <ol>
    <xsl:for-each select=”.//*[local-name()=’note’][@type=’footnote’]”>
    <li>
    <xsl:choose>
    <xsl:when test=”$anchor.id=@*[local-name()=’id’]”>
    <a name=”X”></a>
    <div>
    <xsl:apply-templates/>
    </div>
    </xsl:when>
    <xsl:otherwise>
    <div>
    <xsl:apply-templates/>
    </div>
    </xsl:otherwise>
    </xsl:choose>
    </li>
    </xsl:for-each>
    </ol>
    </xsl:if>

Next tutorial step:

Done!