Difference between revisions of "Endnotes"
m |
Piotr Banski (talk | contribs) m (revert (masking 'display:none' to fool the overzealous spam filter)) |
||
Line 45: | Line 45: | ||
===Create note section=== | ===Create note section=== | ||
− | The following template should be called (using <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 call will most likely be in the template for your document root <code>/</code> or <code>TEI.2</code> templates: |
+ | |||
+ | <pre> | ||
+ | <xsl:template name="notessection"> | ||
+ | <!-- Test if tei:text contains any tei:note elements at any level --> | ||
+ | <xsl:if test="text//note"> | ||
+ | <!-- If yes: add html:hr element and build html:div for the context 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> | ||
+ | <!-- If no: do nothing --> | ||
+ | </xsl:template> | ||
+ | </pre> | ||
+ | |||
+ | ===Build reference marker and link at insertion point=== | ||
+ | This code builds the reference marker and link at the insertion point. The text in <code>html:span[class='hideme']</code> 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: <code>span.hideme {disрlay:none;}</code>).<!-- the entity code serves to fool the spam filter, which is triggered by 'none' as the value of 'display'; otherwise it won't let me save the reverted version --> | ||
+ | |||
+ | <pre> | ||
+ | <!-- match any tei:note element in tei:text --> | ||
+ | <xsl:template match="text//note"> | ||
+ | <!-- Construct the number for the context note by | ||
+ | a) counting all preceding tei:note in tei:text | ||
+ | b) adding 1 to this number --> | ||
+ | <xsl:variable name="notenum" select="count(preceding::note[ancestor::text])+1"/> | ||
+ | <!-- Normalise the spacing for this number --> | ||
+ | <xsl:variable name="linklabel" select="normalize-space($notenum)"/> | ||
+ | <!-- build the link calling the linklable variable --> | ||
+ | <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="$linklabel"/> | ||
+ | <span class="hideme">]</span></a></sup> | ||
+ | <xsl:text> </xsl:text> | ||
+ | </xsl:template> | ||
+ | </pre> | ||
+ | |||
+ | ===Output note content at desired location=== | ||
+ | This code outputs the not content at the desired location in the output document. Each note is a <code>html:div[class="footnote"]</code> containing one or more <code>html:p</code>. The link back to the insertion point is the note number. | ||
+ | |||
+ | <pre> | ||
+ | <!-- Match all tei:note elements in tei:text | ||
+ | when called by an xsl:apply-template mode="shownotes" --> | ||
+ | <xsl:template match="text//note" mode="shownotes"> | ||
+ | <!-- Generate note number as above --> | ||
+ | <xsl:variable name="notenum" select="count(preceding::note[ancestor::text])+1"/> | ||
+ | <xsl:variable name="linklabel" select="normalize-space($notenum)"/> | ||
+ | <!-- output tei:note | ||
+ | a) build wrapper --> | ||
+ | <div class="footnote"> | ||
+ | <!-- test if tei:p[parent::tei:note] is first --> | ||
+ | <xsl:if test="p[position()=1]"> | ||
+ | <!-- If yes, build html:p, placing note number at beginning --> | ||
+ | <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> | ||
+ | <!-- If no output as html:p --> | ||
+ | <xsl:for-each select="p[not(position()=1)]"> | ||
+ | <p> | ||
+ | <xsl:apply-templates select="."/> | ||
+ | </p> | ||
+ | </xsl:for-each> | ||
+ | </div> | ||
+ | </xsl:template> | ||
+ | </pre> | ||
+ | |||
+ | ==Limitations, assumptions, and quirks== | ||
+ | This xslt code is subject to the following limitations, assumptions, and quirks | ||
+ | |||
+ | #all <code>tei:note</code> elements must contain at least one <code>tei:p</code> (it is not hard to adjust the code for notes that contain <code>CDATA</code>, however. | ||
+ | #the note content is output to <code>html:div</code> rather than <code>html:p</code>, since each note is understood as a collection of paragraphs. | ||
+ | |||
+ | [[Category:XSLT]] | ||
+ | [[Category:XSLT:1.0]] | ||
+ | [[Category:XSLT:2.0]] | ||
+ | [[Category:TEI:note]] | ||
+ | [[category:HTML]] | ||
+ | [[Category:TEI:P4]] | ||
+ | [[Category:TEI:P5]] |
Revision as of 13:20, 23 June 2007
This xslt transforms tei:note
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.
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 call will most likely be in the template for your document root /
or TEI.2
templates:
<xsl:template name="notessection"> <!-- Test if tei:text contains any tei:note elements at any level --> <xsl:if test="text//note"> <!-- If yes: add html:hr element and build html:div for the context 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> <!-- If no: do nothing --> </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 {disрlay:none;}
).
<!-- match any tei:note element in tei:text --> <xsl:template match="text//note"> <!-- Construct the number for the context note by a) counting all preceding tei:note in tei:text b) adding 1 to this number --> <xsl:variable name="notenum" select="count(preceding::note[ancestor::text])+1"/> <!-- Normalise the spacing for this number --> <xsl:variable name="linklabel" select="normalize-space($notenum)"/> <!-- build the link calling the linklable variable --> <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="$linklabel"/> <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.
<!-- Match all tei:note elements in tei:text when called by an xsl:apply-template mode="shownotes" --> <xsl:template match="text//note" mode="shownotes"> <!-- Generate note number as above --> <xsl:variable name="notenum" select="count(preceding::note[ancestor::text])+1"/> <xsl:variable name="linklabel" select="normalize-space($notenum)"/> <!-- output tei:note a) build wrapper --> <div class="footnote"> <!-- test if tei:p[parent::tei:note] is first --> <xsl:if test="p[position()=1]"> <!-- If yes, build html:p, placing note number at beginning --> <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> <!-- If no output as html:p --> <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 onetei:p
(it is not hard to adjust the code for notes that containCDATA
, however. - the note content is output to
html:div
rather thanhtml:p
, since each note is understood as a collection of paragraphs.