Difference between revisions of "Endnotes"
m |
(Tried another organisation) |
||
Line 11: | Line 11: | ||
</pre> | </pre> | ||
− | ==Output XHTML 1.0 (Strict)== | + | ==Output== |
+ | ===XHTML 1.0 (Strict)=== | ||
At the insertion point: | At the insertion point: | ||
Line 41: | Line 42: | ||
==XSLT== | ==XSLT== | ||
+ | The same stylesheet works in [[xslt 1.0]] and [[xslt 2.0]]. | ||
+ | |||
===Create note section=== | ===Create note section=== | ||
The following template should be called (using <code><xsl:call-template name="notessection"/></code>) at the point at which you wish the notes to appear in your output document. This will most likely be in the template for your document root <code>/</code>, <code>TEI.2</code>, or <code>text</code>. To avoid problems with <code>note</code> elements elsewhere in the tei document (e.g. in <code>tei:teiHeader/notesStmt</code>), the following can be substituted for the first <code>xsl:if</code> test: <code>body//note</code>: | The following template should be called (using <code><xsl:call-template name="notessection"/></code>) at the point at which you wish the notes to appear in your output document. This will most likely be in the template for your document root <code>/</code>, <code>TEI.2</code>, or <code>text</code>. To avoid problems with <code>note</code> elements elsewhere in the tei document (e.g. in <code>tei:teiHeader/notesStmt</code>), the following can be substituted for the first <code>xsl:if</code> test: <code>body//note</code>: |
Revision as of 17:36, 21 April 2005
This xslt transforms tei:note
elements for display in xhtml. It places a numbered marker at the insertion point and reproduced the note content in a separate section at the end of the document. Links between the insertion marker and note are automatically generated.
Contents
Input TEI
<p>...Lorem ipsum dolor sit amet, consectetuer adipiscing elit.<note><p>Suspendisse faucibus. Nulla a tortor id pede aliquam venenatis.</p> <p>Donec eget lectus.</p></note> Fusce hendrerit, quam ac nonummy rutrum, turpis odio ultrices tortor...</p>
Output
XHTML 1.0 (Strict)
At the insertion point:
<p>...Lorem ipsum dolor sit amet, consectetuer adipiscing elit.<sup><a name="refpoint-1" href="#note-1" title="Link to note 1 at the end of this document."><span class="hideme">[</span>1<span class="hideme">]</span></a></sup> Fusce hendrerit, quam ac nonummy rutrum, turpis odio ultrices tortor...</p>
Elsewhere in the document
<hr class="subdivider"/> <div class="notes"> <h2><a id="notes"/>Notes:</h2> <div class="footnote"><p> <a id="note-1" href="#refpoint-1" title="Link to insertion point of note in main text."><span class="hideme">[</span>1<span class="hideme">]</span></a>. Suspendisse faucibus. Nulla a tortor id pede aliquam venenatis.</p> <p>Donec eget lectus.</p> </div> [other html:div[class='note']] </div>
XSLT
The same stylesheet works in xslt 1.0 and xslt 2.0.
Create note section
The following template should be called (using <xsl:call-template name="notessection"/>
) at the point at which you wish the notes to appear in your output document. This will most likely be in the template for your document root /
, TEI.2
, or text
. To avoid problems with note
elements elsewhere in the tei document (e.g. in tei:teiHeader/notesStmt
), the following can be substituted for the first xsl:if
test: body//note
:
<xsl:template name="notessection"> <xsl:if test="note"> <hr class="subdivider"/> <div class="notes"> <h2><a id="notes"/>Notes:</h2> <xsl:for-each select=".//note"> <xsl:apply-templates select="." mode="shownotes"/> </xsl:for-each></div> </xsl:if> </xsl:template>
Build reference marker and link at insertion point
This code builds the reference marker and link at the insertion point. The text in html:span[class='hideme']
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: span.hideme {display:none;}
).
<xsl:template match="text//note"> <xsl:variable name="notenum" select="count(preceding::note[ancestor::text])+1"/> <xsl:variable name="linklabel" select="normalize-space($notenum)"/> <sup><a> <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> <span class="hideme">[</span><xsl:value-of select="normalize-space($notenum)"/><span class="hideme">]</span></a></sup> <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 html:div[class="footnote"]
containing one or more html:p
. The link back to the insertion point is the note number.
<xsl:template match="text//note" mode="shownotes"> <xsl:variable name="notenum" select="count(preceding::note[ancestor::text])+1"/> <xsl:variable name="linklabel" select="normalize-space($notenum)"/> <div class="footnote"> <xsl:if test="p[position()=1]"> <p> <a> <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> <span class="hideme">[</span> <xsl:value-of select="$notenum"/> <span class="hideme">]</span> </a><xsl:text>. </xsl:text> <xsl:apply-templates select="p[position()=1]"/> </p> </xsl:if> <xsl:for-each select="p[not(position()=1)]"> <p> <xsl:apply-templates select="."/> </p> </xsl:for-each> </div> </xsl:template>
Limitations, assumptions, and quirks
This xslt code is subject to the following limitations, assumptions, and quirks
- all tei:note elements must contain at least one tei:p (it is not hard to adjust the code for notes that contain CDATA, however.
- the note content is output to html:div rather than html:p, since each note is understood as a collection of paragraphs.