Difference between revisions of "Endnotes"
(→Limitations, assumptions, and quirks) |
Piotr Banski (talk | contribs) m (→XSLT: caps in links (will make them redirects)) |
||
| (12 intermediate revisions by 4 users not shown) | |||
| Line 1: | Line 1: | ||
| − | This xslt transforms <code>tei:note</code> elements for display in xhtml. It places a numbered marker at the insertion point and | + | This xslt transforms <code>tei:note</code> 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== | ==Input TEI== | ||
| Line 37: | Line 37: | ||
<p>Donec eget lectus.</p> | <p>Donec eget lectus.</p> | ||
</div> | </div> | ||
| − | [other html:div[class='note']] | + | <!-- [other html:div[class='note']] --> |
</div> | </div> | ||
</pre> | </pre> | ||
==XSLT== | ==XSLT== | ||
| − | The same stylesheet works in [[ | + | 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 call will most likely be in the template for your document root <code>/</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> | <pre> | ||
<xsl:template name="notessection"> | <xsl:template name="notessection"> | ||
| − | <xsl:if test="note"> | + | <!-- 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"/> | <hr class="subdivider"/> | ||
<div class="notes"> | <div class="notes"> | ||
| Line 57: | Line 59: | ||
</xsl:for-each></div> | </xsl:for-each></div> | ||
</xsl:if> | </xsl:if> | ||
| + | <!-- If no: do nothing --> | ||
</xsl:template> | </xsl:template> | ||
</pre> | </pre> | ||
===Build reference marker and link at insertion point=== | ===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 { | + | 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> | <pre> | ||
| + | <!-- match any tei:note element in tei:text --> | ||
<xsl:template match="text//note"> | <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"/> | <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)"/> | <xsl:variable name="linklabel" select="normalize-space($notenum)"/> | ||
| + | <!-- build the link calling the linklable variable --> | ||
<sup><a> | <sup><a> | ||
<xsl:attribute name="name">refpoint-<xsl:value-of select="$linklabel"/></xsl:attribute> | <xsl:attribute name="name">refpoint-<xsl:value-of select="$linklabel"/></xsl:attribute> | ||
| Line 72: | Line 81: | ||
<xsl:attribute name="title">Link to note <xsl:value-of select="$linklabel"/> | <xsl:attribute name="title">Link to note <xsl:value-of select="$linklabel"/> | ||
at the end of this document.</xsl:attribute> | at the end of this document.</xsl:attribute> | ||
| − | <span class="hideme">[</span><xsl:value-of select=" | + | <span class="hideme">[</span><xsl:value-of select="$linklabel"/> |
<span class="hideme">]</span></a></sup> | <span class="hideme">]</span></a></sup> | ||
<xsl:text> </xsl:text> | <xsl:text> </xsl:text> | ||
| Line 82: | Line 91: | ||
<pre> | <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"> | <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="notenum" select="count(preceding::note[ancestor::text])+1"/> | ||
<xsl:variable name="linklabel" select="normalize-space($notenum)"/> | <xsl:variable name="linklabel" select="normalize-space($notenum)"/> | ||
| + | <!-- output tei:note | ||
| + | a) build wrapper --> | ||
<div class="footnote"> | <div class="footnote"> | ||
| + | <!-- test if tei:p[parent::tei:note] is first --> | ||
<xsl:if test="p[position()=1]"> | <xsl:if test="p[position()=1]"> | ||
| + | <!-- If yes, build html:p, placing note number at beginning --> | ||
<p> | <p> | ||
<a> | <a> | ||
| Line 100: | Line 116: | ||
</p> | </p> | ||
</xsl:if> | </xsl:if> | ||
| + | <!-- If no output as html:p --> | ||
<xsl:for-each select="p[not(position()=1)]"> | <xsl:for-each select="p[not(position()=1)]"> | ||
<p> | <p> | ||
| Line 112: | Line 129: | ||
This xslt code is subject to the following 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. | + | #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. | #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: | + | [[Category:XSLT:1.0]] |
| − | [[Category: | + | [[Category:XSLT:2.0]] |
| − | [[Category:TEI: | + | [[Category:TEI:note]] |
[[category:HTML]] | [[category:HTML]] | ||
| − | [[Category: | + | [[Category:TEI:P4]] |
| − | [[Category: | + | [[Category:TEI:P5]] |
Latest revision as of 14:08, 22 November 2008
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:noteelements 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:divrather thanhtml:p, since each note is understood as a collection of paragraphs.