Difference between revisions of "LineNumber.xsl"
Jump to navigation
Jump to search
Filologanoga (talk | contribs) (→Stylesheet) |
Filologanoga (talk | contribs) (→Stylesheet) |
||
Line 28: | Line 28: | ||
<pre> | <pre> | ||
<?xml version="1.0" encoding="UTF-8"?> | <?xml version="1.0" encoding="UTF-8"?> | ||
+ | |||
<!-- Retain only text, but number every 5th line of poetry, P5 version --> | <!-- Retain only text, but number every 5th line of poetry, P5 version --> | ||
<!-- An exercise done and tested in oXygen --> | <!-- An exercise done and tested in oXygen --> | ||
− | + | <!-- Neven Jovanović, 2008 --> | |
+ | |||
<xsl:stylesheet xmlns:tei="http://www.tei-c.org/ns/1.0" | <xsl:stylesheet xmlns:tei="http://www.tei-c.org/ns/1.0" | ||
xmlns="http://www.w3.org/1999/xhtml" | xmlns="http://www.w3.org/1999/xhtml" | ||
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> | xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> | ||
+ | |||
<xsl:output method = "text" /> | <xsl:output method = "text" /> | ||
<xsl:template match="/tei:TEI/tei: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"> | <xsl:for-each select="//tei:l"> | ||
<!-- select only verse lines; should be improved for collections of poems etc. --> | <!-- select only verse lines; should be improved for collections of poems etc. --> | ||
+ | |||
<xsl:choose> | <xsl:choose> | ||
<xsl:when test="(position() mod 5 = 0)"> | <xsl:when test="(position() mod 5 = 0)"> | ||
Line 46: | Line 51: | ||
<!-- E. g. 11 mod 4 equals 3, because 4 goes into 11 twice with 3 left over." --> | <!-- 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. --> | <!-- We check whether line number divides into 5 evenly, testing whether the line number mod 5 equals zero. --> | ||
+ | |||
<xsl:text > | <xsl:text > | ||
[</xsl:text> | [</xsl:text> | ||
Line 52: | Line 58: | ||
<xsl:value-of select = "." /> | <xsl:value-of select = "." /> | ||
</xsl:when> | </xsl:when> | ||
+ | |||
<xsl:otherwise> | <xsl:otherwise> | ||
<xsl:text > | <xsl:text > | ||
Line 58: | Line 65: | ||
<xsl:value-of select = "." /> | <xsl:value-of select = "." /> | ||
</xsl:otherwise> | </xsl:otherwise> | ||
+ | |||
</xsl:choose> | </xsl:choose> | ||
+ | |||
</xsl:for-each> | </xsl:for-each> | ||
+ | |||
<!-- adapted from www.zvon.org and Bob DuCharme on whitespace --> | <!-- adapted from www.zvon.org and Bob DuCharme on whitespace --> | ||
+ | |||
</xsl:template> | </xsl:template> | ||
</xsl:stylesheet> | </xsl:stylesheet> |
Revision as of 22:51, 4 September 2008
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.
Known Restrictions or Problems
Text only. Numbers lines consecutively, therefore it 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, Math and XSLT, 2001.
- DuCharme, Bob, Controlling Whitespace, Part Three, 2002.
- 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>