Endnotes

This xslt transforms  elements for display in xhtml. It places a numbered marker at the insertion point and reproduces the note content in a separate section at the end of the document. Links between the insertion marker and note are automatically generated.

Input TEI
...Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Suspendisse faucibus. Nulla a tortor id pede aliquam venenatis. Donec eget lectus. Fusce hendrerit, quam ac nonummy rutrum, turpis odio ultrices tortor...

XHTML 1.0 (Strict)
At the insertion point:

...Lorem ipsum dolor sit amet, consectetuer adipiscing elit.  [ 1]  Fusce hendrerit, quam ac nonummy rutrum, turpis odio ultrices tortor...

Elsewhere in the document

Notes:  [ 1] . Suspendisse faucibus. Nulla a tortor id pede aliquam venenatis. Donec eget lectus.

XSLT
The same stylesheet works in XSLT 1.0 and XSLT 2.0.

Create note section
The following template should be called (using ) at the point at which you wish the notes to appear in your output document. This call will most likely be in the template for your document root  or    templates:

  Notes:     

Build reference marker and link at insertion point
This code builds the reference marker and link at the insertion point. The text in  is for use when CSS styles are turned off or in accessibility devices (To ensure they do not appear when the styles are turned on, place the following in your CSS:  ).

    <xsl:attribute name="name">refpoint-<xsl:value-of select="$linklabel"/></xsl:attribute> <xsl:attribute name="href">#note-<xsl:value-of select="$linklabel"/></xsl:attribute> <xsl:attribute name="title">Link to note <xsl:value-of select="$linklabel"/> at the end of this document.</xsl:attribute> [ <xsl:value-of select="$linklabel"/> ] </a> <xsl:text> </xsl:text> </xsl:template>

Output note content at desired location
This code outputs the not content at the desired location in the output document. Each note is a  containing one or more. The link back to the insertion point is the note number.

 <xsl:variable name="notenum" select="count(preceding::note[ancestor::text])+1"/> <xsl:variable name="linklabel" select="normalize-space($notenum)"/> <xsl:if test="p[position=1]">  <xsl:attribute name="id">note-<xsl:value-of select="$linklabel"/></xsl:attribute> <xsl:attribute name="href">#refpoint-<xsl:value-of select="$linklabel"/></xsl:attribute> <xsl:attribute name="title"><xsl:text>Link to insertion point of note in main text.</xsl:text></xsl:attribute> [      <xsl:value-of select="$notenum"/> ]        </a><xsl:text>. </xsl:text> <xsl:apply-templates select="p[position=1]"/> </xsl:if> <xsl:for-each select="p[not(position=1)]"> <xsl:apply-templates select="."/> </xsl:for-each> </xsl:template>

Limitations, assumptions, and quirks
This xslt code is subject to the following limitations, assumptions, and quirks


 * 1) all  elements must contain at least one   (it is not hard to adjust the code for notes that contain , however.
 * 2) the note content is output to  rather than , since each note is understood as a collection of paragraphs.