LineNumber.xsl
Jump to navigation
Jump to search
Contents
Summary
This is a XSLT script for adding a line number to each fifth line of poetry. Such numbering is standard in scholarly editions.
This is also one of my first exercises in writing XSL; it would be interesting to see how it could be improved.
Add any comments to the 'discussion' tab.
Required Input
Any TEI XML file, preferably with "l" elements in it.
Expected Output
Text only, but with line counts added in every fifth verse, enclosed in square brackets. All lines are indented by one tab and several spaces.
Known Restrictions or Problems
Text only. Numbers lines consecutively, therefore is not appropriate for collections of poems, or for poems with several cantos etc.
Bibliography
- Bauman, Syd, Count_Metrical_Lines_P5.xslt, 2006.
- DuCharme, Bob, Controlling Whitespace, Part Three, 2002.
- DuCharme, Bob, Math and XSLT, 2001.
- Nic, Miloslav, ZVON XSLT Reference, 2002.
Stylesheet
<?xml version="1.0" encoding="UTF-8"?> <!-- Retain only text, but number every 5th line of poetry, P5 version --> <!-- An exercise done and tested in oXygen --> <!-- Neven Jovanović, 2008 --> <xsl:stylesheet xmlns:tei="http://www.tei-c.org/ns/1.0" xmlns="http://www.w3.org/1999/xhtml" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> <xsl:output method = "text" /> <xsl:template match="/tei:TEI/tei:text"> <!-- The line above was lifted from Syd Bauman's TEI stylesheet for lines of poetry --> <xsl:for-each select="//tei:l"> <!-- select only verse lines; should be improved for collections of poems etc. --> <xsl:choose> <xsl:when test="(position() mod 5 = 0)"> <!-- Taken from XSLT math operations by Bob DuCharme: --> <!-- "the mod operator shows the remainder if you divide the first term by the second. --> <!-- E. g. 11 mod 4 equals 3, because 4 goes into 11 twice with 3 left over." --> <!-- We check whether line number divides into 5 evenly, testing whether the line number mod 5 equals zero. --> <xsl:text > [</xsl:text> <xsl:value-of select = "position()" /> <xsl:text >] </xsl:text> <xsl:value-of select = "." /> </xsl:when> <xsl:otherwise> <xsl:text > </xsl:text> <!-- another by Bob DuCharme: pretty-printing with tabs ( ) --> <xsl:value-of select = "." /> </xsl:otherwise> </xsl:choose> </xsl:for-each> <!-- adapted from www.zvon.org and Bob DuCharme on whitespace --> </xsl:template> </xsl:stylesheet>