summaryrefslogtreecommitdiff
path: root/sandbox/paultremblay/python_interface/docutilsToFo/xsl_fo/line_block.xsl
blob: af0f73282eef675a60150d6fb6edc2713f497d82 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
<xsl:stylesheet 
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:fo="http://www.w3.org/1999/XSL/Format"
    version="1.1"
    >
    <!--
    TODO

    Make different templates for numbered and unnumbered verse, to keep the 
    result clean
    -->
    
    <!-- $Id$ -->
    <xsl:attribute-set name="outer-line-block">
        <xsl:attribute name="space-before">12pt</xsl:attribute>
        <xsl:attribute name="space-after">12pt</xsl:attribute>
    </xsl:attribute-set>


    <!--add text-align-last=justfiy only for numbered verse, so change-->
    <xsl:attribute-set name="level1-line-block">
        <xsl:attribute name="start-indent">10mm</xsl:attribute>
    </xsl:attribute-set>
    
    <xsl:attribute-set name="level2-line-block">
        <xsl:attribute name="start-indent">20mm</xsl:attribute>
    </xsl:attribute-set>

    <xsl:attribute-set name="level3-line-block">
        <xsl:attribute name="start-indent">30mm</xsl:attribute>
    </xsl:attribute-set>

    <xsl:attribute-set name="level4-line-block">
        <xsl:attribute name="start-indent">40mm</xsl:attribute>
    </xsl:attribute-set>

    <xsl:attribute-set name="level5-line-block">
        <xsl:attribute name="start-indent">50mm</xsl:attribute>
    </xsl:attribute-set>

    <xsl:attribute-set name="stanza-title-block">
        <xsl:attribute name="text-align">center</xsl:attribute>
        <xsl:attribute name="space-before">12</xsl:attribute>
        <xsl:attribute name="font-weight">bold</xsl:attribute>
    </xsl:attribute-set>

    <xsl:template match="line_block">
        <xsl:variable name="level" select="count(ancestor::line_block) + 1"/>
        <xsl:choose>
            <xsl:when test="not(parent::line_block) ">
                <fo:block xsl:use-attribute-sets="outer-line-block" role="line-block">
                    <xsl:apply-templates/>
                </fo:block>
            </xsl:when>
            <xsl:otherwise>
                <xsl:apply-templates/>
            </xsl:otherwise>
        </xsl:choose>
    </xsl:template> 


    <xsl:template name="get-line-number">
        <xsl:variable name="top-block-id">
            <xsl:for-each select="ancestor::line_block[last()]">
                <xsl:value-of select="generate-id()"/>
            </xsl:for-each>
        </xsl:variable>
        <xsl:number from="line_block[generate-id() = $top-block-id]" 
            count="line[normalize-space(.) != ''][not(title_reference)][not(inline[@classes='title'])]" level="any"/>
    </xsl:template>

    <xsl:template name="number-line">
        <xsl:variable name="num">
            <xsl:call-template name="get-line-number"/>
        </xsl:variable>
            <xsl:choose>
                <xsl:when test="$num != 0 and ($num +1) mod $number-verse = 1">
                    <fo:leader leader-pattern="space" />
                    <xsl:value-of select="$num"/>
                </xsl:when>
                <xsl:otherwise>
                    <fo:leader leader-pattern="space" />
                </xsl:otherwise>
            </xsl:choose>
    </xsl:template>


    <xsl:template match="line">
        <xsl:choose>
            <xsl:when test="$number-verse != ''">
                <xsl:call-template name="line-with-number"/>
            </xsl:when>
            <xsl:otherwise>
                <xsl:call-template name="line"/>
            </xsl:otherwise>
        </xsl:choose>
    </xsl:template>

    <xsl:template match="line[title_reference]|line[inline[@classes='title']]" priority="2">
        <fo:block xsl:use-attribute-sets="stanza-title-block" role="stanza-title">
            <xsl:apply-templates/>
        </fo:block>
    </xsl:template>

    <xsl:template match="line/title_reference" priority="2">
        <xsl:apply-templates/>
    </xsl:template>

    <xsl:template name="line">
        <xsl:variable name="level" select="count(ancestor::line_block)"/>
        <xsl:choose>
            <xsl:when test="normalize-space(.) = ''">
                <fo:block>
                    <xsl:text>&#x00a0;</xsl:text>
                </fo:block>
            </xsl:when>

            <xsl:when test="$level = 1">
                <fo:block xsl:use-attribute-sets="level1-line-block" role="line">
                    <xsl:apply-templates/>
                </fo:block>
            </xsl:when>
            <xsl:when test="$level = 2">
                <fo:block xsl:use-attribute-sets="level2-line-block" role="line">
                    <xsl:apply-templates/>
                </fo:block>
            </xsl:when>
            <xsl:when test="$level = 3">
                <fo:block xsl:use-attribute-sets="level3-line-block" role="line">
                    <xsl:apply-templates/>
                </fo:block>
            </xsl:when>
            <xsl:when test="$level = 4">
                <fo:block xsl:use-attribute-sets="level4-line-block" role="line">
                    <xsl:apply-templates/>
                </fo:block>
            </xsl:when>
            <xsl:when test="$level = 5">
                <fo:block xsl:use-attribute-sets="level5-line-block" role="line">
                    <xsl:apply-templates/>
                </fo:block>
            </xsl:when>
            <xsl:otherwise>
                <xsl:variable name="msg">
                    <xsl:text>Cannot process line_blocks more than 5 levels deep.</xsl:text>
                </xsl:variable>
                <xsl:call-template name="error-message">
                    <xsl:with-param name="text" select="$msg"/>
                </xsl:call-template>
            </xsl:otherwise>
        </xsl:choose>
    </xsl:template>


    <xsl:template name="line-with-number">
        <xsl:variable name="level" select="count(ancestor::line_block)"/>
        <xsl:choose>
            <xsl:when test="normalize-space(.) = ''">
                <fo:block>
                    <xsl:text>&#x00a0;</xsl:text>
                </fo:block>
            </xsl:when>
            <xsl:when test="$level = 1">
                <fo:block xsl:use-attribute-sets="level1-line-block" text-align-last = "justify" role="line">
                    <xsl:apply-templates/>
                    <xsl:call-template name="number-line"/>
                </fo:block>
            </xsl:when>
            <xsl:when test="$level = 2">
                <fo:block xsl:use-attribute-sets="level2-line-block" text-align-last = "justify" role="line">
                    <xsl:apply-templates/>
                    <xsl:call-template name="number-line"/>
                </fo:block>
            </xsl:when>
            <xsl:when test="$level = 3">
                <fo:block xsl:use-attribute-sets="level3-line-block" text-align-last = "justify" role="line">
                    <xsl:apply-templates/>
                    <xsl:call-template name="number-line"/>
                </fo:block>
            </xsl:when>
            <xsl:when test="$level = 4">
                <fo:block xsl:use-attribute-sets="level4-line-block" text-align-last = "justify" role="line">
                    <xsl:apply-templates/>
                    <xsl:call-template name="number-line"/>
                </fo:block>
            </xsl:when>
            <xsl:when test="$level = 5">
                <fo:block xsl:use-attribute-sets="level5-line-block" text-align-last = "justify" role="line">
                    <xsl:apply-templates/>
                    <xsl:call-template name="number-line"/>
                </fo:block>
            </xsl:when>
            <xsl:otherwise>
                <xsl:variable name="msg">
                    <xsl:text>Cannot process line_blocks more than 5 levels deep.</xsl:text>
                </xsl:variable>
                <xsl:call-template name="error-message">
                    <xsl:with-param name="text" select="$msg"/>
                </xsl:call-template>
            </xsl:otherwise>
        </xsl:choose>
    </xsl:template>

    <xsl:template match="inline[@classes='title']"/>

</xsl:stylesheet>