Captions and boilerplate text abstracted
Posted by mholmes on 13 Oct 2011 in Activity log
I've implemented a system whereby captions and other boilerplate text content is abstracted from the XHTML and/or TEI code and stored in /db/data/boilerplate/boilerplate.xml
. This is how it works:
/db/data/boilerplate/boilerplate.xml
contains individual<div>
s,<seg>
s etc. which are identified by @xml:id and contain the text snippets. The bulk of the items, which are very short, are stored in<seg>
elements which look like this:<seg xml:id="sshrcFundedCaption">This research was supported by the Social Sciences and Humanities Research Council.</seg>
- The
includes.xql
module retrieves these, and makes them available in two forms: one as a sequence of items that can be accessed from XQuery (where XQuery itself is constructing the output and requires the captions), and one in the form of<param>
elements which can be passed on to XSLT transformations (where XSLT will require the snippets to use when constructing XHTML output). This is the code fromincludes.xql
:declare variable $inc:captions := doc('/db/data/boilerplate/boilerplate.xml')//tei:div[@xml:id='captions']; declare variable $inc:captionParams := for $inc:c in $inc:captions//tei:seg return <param name="{$inc:c/@xml:id}" value="{$inc:c/text()}"/>;
- XQuery makes use of these items like this:
<p>{$inc:captions//tei:seg[@xml:id='sshrcFundedCaption']/text()}</p>
- The main XSLT library,
general.xsl
, includes a module calledcaptions.xsl
, which defines parameters (along with default values); when the XQuery engine calls the transformer, it passes values for these parameters in. For instance:<xsl:param name="sshrcFundedCaption">This research was supported by the Social Sciences and Humanities Research Council.</xsl:param>
The XSLT can then use the params like this:<xsl:value-of select="$mapCaption"/>
There are two significant advantages to this, which make it worth the work. First, the boilerplate.xml file lives in the /db/data collection, which makes it editable by the data editors, so e.g. JJ can modify captions etc. if necessary. Second, if the site ever needed to be translated into French or another language, the text components are already centralized, so that would be easier.