Making Page Breaks Visible

One of the surprising challenges of transforming Digital Day Thoughts into a web version was making page breaks in the source material readily visible. Part of the fun (or frustration, depending on mood) of working with text in XML and XSL is figuring out the logic of hierarchy. I determined that a simple horizontal line would be the simplest means of distinguishing pages, but I couldn’t figure how to create one within the template match for the page break itself—I would have to insert the graphic lines through a template match for the poetry lines, and this proved thorny. For those who are undertaking similar “small” challenges in XSLT, I am going to include an annotated description of my XSL code here.

First, the code:

<xsl:template match="tei:l">
        
        <xsl:variable name="PageChecker" select="name(preceding-sibling::*[1])"></xsl:variable>
     
        <xsl:variable name="PageAssigner" select="preceding-sibling::*[1]/@edRef"></xsl:variable>
        
        <!--To check whether there are page breaks in BOTH the quarto and octavo -->
        <xsl:variable name="PageAssignerBoth" select="preceding-sibling::*[2]/@edRef"></xsl:variable>
 
       
        <xsl:choose>
            
            <xsl:when test="$PageChecker='pb' and $PageAssignerBoth='#Q'">
                
                <xsl:text disable-output-escaping='yes'>&lt;p class="quartoPageBreak quartoPageBreak"&gt;</xsl:text>
                
            </xsl:when>
            
            <xsl:when test="$PageChecker='pb' and $PageAssigner='#Q'">
                
                <xsl:text disable-output-escaping='yes'>&lt;p class="quartoPageBreak"&gt;</xsl:text>                              
                
            </xsl:when>
            
            <xsl:when test="$PageChecker='pb' and $PageAssigner='#O'">
                
                <xsl:text disable-output-escaping='yes'>&lt;p class="octavoPageBreak"&gt;</xsl:text>
                
            </xsl:when>
            
            
            <xsl:otherwise>
                <xsl:text disable-output-escaping='yes'>&lt;p&gt;</xsl:text>
                
            </xsl:otherwise>
            
        </xsl:choose>
        
        
        <!-- If it's a new paragraph, we need to insert a couple spaces as an indent. Looking for a null value, because a first <l> in an <lg> will have no preceding-sibling. -->
        
        <xsl:choose>
            
            <xsl:when test="$PageChecker=''">
                <xsl:text>&#160;&#160;</xsl:text>
            </xsl:when>
                      
        </xsl:choose>
        
        
        <xsl:apply-templates/>
        
        <span class="quarto_changes"><xsl:for-each select="tei:app/tei:rdg[@wit='#Q']"><xsl:value-of select='.'/><xsl:text> | </xsl:text> </xsl:for-each></span>
        <span class="octavo_changes"><xsl:for-each select="tei:app/tei:rdg[@wit='#O']"><xsl:value-of select='.'/><xsl:text> | </xsl:text> </xsl:for-each></span>
                 
        <xsl:text disable-output-escaping='yes'>&lt;/p&gt;</xsl:text>
        
</xsl:template>

 

Now, an explanation. If you would like to consult the XML of Digital Day Thoughts, you can access it from the link on Scholars Grotto (http://scholarsgrotto.com/Day%20Thoughts/DayThoughts.php).

First, I define three variables. “PageChecker” identifies the element immediately preceding the current line of poetry. In my XML, self enclosing page breaks, <pb/>, reside on the same axis as lines, <l>, so this PageChecker variable is a fairly simple means of determining whether the current line of poetry follows a page break.

“PageAssigner” then grabs the value of the “edRef,” or edition reference, attribute of that preceding element. This will tell us whether the page break occurs in the quarto or octavo edition.

“PageAssignerBoth” is a little trickier, a touch kludgy even, but logical. It basically determines whether we have a page break in BOTH the quarto and octavo printings by checking the edition reference attribute TWO elements back. My practice throughout the encoding was to write the quarto page break first, so if both printings have a break at the same place, the second element back from the current line will always have an edition reference of “#Q” (quarto) as so:

<pb edRef=”#Q”/>
<pb edRef=”#O”/>
<l>This is my line of text</l>

After defining these variables, we then get into what looks like an elaborate choice tree. But it is, I think, fairly simple once one ponders it a minute. First test: if the element preceding the current line is a page break, and if the edition reference two elements back from the current line indicates the quarto, we know there has to be a page break in both printings of the poem. Thus, we start a new html paragraph <p> with stylesheet classes indicating quartoPageBreak and octavoPageBreak. (These CSS classes generate an overline effect.) If this test succeeds, the loop exits.

If the first test fails, the next two tests check whether a singular page break occurs in the quarto or the octavo edition and assigns a stylesheet class accordingly.

The “otherwise” test simply generates a new html paragraph without any stylesheet classes. No page break there.

Next, we see another xsl:choose element, designed to insert two spaces at the beginning of a new verse paragraph. Here, the PageChecker variable comes in handy again. Recall that this variable tells us what the element preceding the current line is. Most of the time, its value is simply another line. Some of the time it is a page break, as we have seen. But if the current line of poetry is the first line in a verse paragraph (represented as a line group, <lg>, which is an ancestor to lines <l>), then there are no preceding sibling elements. PageChecker will return a null value, which is accordingly the test condition for this xsl:choose.

Notice that we haven’t actually done anything with the line of text yet. All we’ve done is assign style classes to a new html paragraph, and if necessary, added two spaces. Finally, after all this setup, we get the <xsl:apply-templates/>, which will spit out the text.

But we are not done. For the sake of brevity, I’ll just say that the next two <span> elements aggregate all the changes unique to the quarto and to the octavo printings of the line, and these remain hidden until the user chooses to make them visible by comparing editions with the “Transformation” toolbox on the web interface.

Last, but certainly not least, we end by closing up the html paragraph, </p>.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>