summaryrefslogtreecommitdiff
path: root/sandbox/paultremblay/python_interface/docutilsToFo/xsl_fo/util.xsl
blob: 22a00882385b716d2cf0b199fb9fe6271a75ded5 (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
<xsl:stylesheet 
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:fo="http://www.w3.org/1999/XSL/Format"
    version="1.1"
    >
    <!-- $Id$ -->


    <xsl:variable name="toc-exists">
        <xsl:if test="/document/topic[@classes='contents']">True</xsl:if>
    </xsl:variable>
    <xsl:variable name="dedication-exists">
        <xsl:if test="/document/topic[@classes='dedication']">True</xsl:if>
    </xsl:variable>
    <xsl:variable name="abstract-exists">
        <xsl:if test="/document/topic[@classes='abstract']">True</xsl:if>
    </xsl:variable>
    <xsl:variable name="title-exists">
        <xsl:if test="/document/title">True</xsl:if>
    </xsl:variable>
    <xsl:variable name="bibliographic-exists">
        <xsl:if test="/document/docinfo">True</xsl:if>
    </xsl:variable>
    <!--determine page sequence, to be used in other templates-->
    <xsl:variable name="page-sequence-type">
        <xsl:variable name="need-front-matter-page-sequence">
            <xsl:choose>
                <xsl:when test="$title-exists='True' and $title-pagination='with-front'">True</xsl:when>
                <xsl:when test="$bibliographic-exists='True' and $bibliographic-pagination='with-front'">True</xsl:when>
                <xsl:when test="$abstract-exists='True' and $abstract-pagination='with-front'">True</xsl:when>
                <xsl:when test="$dedication-exists='True' and $dedication-pagination='with-front'">True</xsl:when>
                <xsl:when test="$toc-exists='True' and $toc-pagination='with-front'">True</xsl:when>
                <xsl:otherwise>False</xsl:otherwise>
            </xsl:choose>
        </xsl:variable>
        <xsl:variable name="need-toc-page-sequence">
            <xsl:choose>
                <xsl:when test="$title-exists='True' and $title-pagination='with-toc'">True</xsl:when>
                <xsl:when test="$bibliographic-exists='True' and $bibliographic-pagination='with-toc'">True</xsl:when>
                <xsl:when test="$abstract-exists='True' and $abstract-pagination='with-toc'">True</xsl:when>
                <xsl:when test="$dedication-exists='True' and $dedication-pagination='with-toc'">True</xsl:when>
                <xsl:when test="$toc-exists='True' and $toc-pagination='with-toc'">True</xsl:when>
                <xsl:otherwise>False</xsl:otherwise>
            </xsl:choose>
        </xsl:variable>
        <xsl:choose>
            <xsl:when test="$need-toc-page-sequence = 'True' and $need-front-matter-page-sequence = 'True'">
                <xsl:text>front-toc-body</xsl:text>
            </xsl:when>
            <xsl:when test="$need-front-matter-page-sequence = 'True'">
                <xsl:text>front-body</xsl:text>
            </xsl:when>
            <xsl:when test="$need-toc-page-sequence = 'True'">
                <xsl:text>toc-body</xsl:text>
            </xsl:when>
            <xsl:when test="$need-toc-page-sequence = 'False' and $need-front-matter-page-sequence = 'False'">
                <xsl:text>body</xsl:text>
            </xsl:when>
            <xsl:otherwise>
                <xsl:message terminate = "yes">
                    <xsl:text>Stylsheet error: no page sequence found</xsl:text>
                </xsl:message>
            </xsl:otherwise>
        </xsl:choose>
    </xsl:variable>

    <xsl:variable name="layout-page">
        <xsl:choose>
            <xsl:when test = "$page-layout != ''">
                <xsl:value-of select="$page-layout"/>
            </xsl:when>
            <xsl:when test = "/document/container[@classes = 'body-header']|/document/container[@classes='body-footer']">
                <xsl:text>first</xsl:text> 
            </xsl:when>
            <xsl:when test = "/document/container[@classes = 'toc-body-header']|/document/container[@classes='toc-body-footer']">
                <xsl:text>first</xsl:text> 
            </xsl:when>
            <xsl:when test = "/document/container[@classes = 'first-header']|/document/container[@classes='first-footer']">
                <xsl:choose>
                    <xsl:when test="/document/container[@classes = 'odd-header']|/document/container[@classes = 'odd-footer']">
                        <xsl:text>first-odd-even</xsl:text> 
                    </xsl:when>
                    <xsl:when test="/document/container[@classes = 'even-header']|/document/container[@classes = 'even-footer']">
                        <xsl:text>first-odd-even</xsl:text> 
                    </xsl:when>
                    <xsl:otherwise>
                        <xsl:text>first</xsl:text>
                    </xsl:otherwise>
                </xsl:choose>
            </xsl:when>
            <xsl:when test = "/document/container[@classes = 'toc-first-header']|/document/container[@classes='toc-first-footer']">
                <xsl:choose>
                    <xsl:when test="/document/container[@classes = 'toc-odd-header']|/document/container[@classes = 'toc-odd-footer']">
                        <xsl:text>first-odd-even</xsl:text> 
                    </xsl:when>
                    <xsl:when test="/document/container[@classes = 'toc-even-header']|/document/container[@classes = 'toc-even-footer']">
                        <xsl:text>first-odd-even</xsl:text> 
                    </xsl:when>
                    <xsl:otherwise>
                        <xsl:text>first</xsl:text>
                    </xsl:otherwise>
                </xsl:choose>
            </xsl:when>
            <xsl:when test = "/document/container[@classes = 'odd-header']|/document/container[@classes='odd-footer']">
                <xsl:text>odd-even</xsl:text>
            </xsl:when>
            <xsl:when test = "/document/container[@classes = 'toc-odd-header']|/document/container[@classes='toc-odd-footer']">
                <xsl:text>odd-even</xsl:text>
            </xsl:when>
            <xsl:when test = "/document/container[@classes = 'even-header']|/document/container[@classes='even-footer']">
                <xsl:text>odd-even</xsl:text>
            </xsl:when>
            <xsl:when test = "/document/container[@classes = 'toc-even-header']|/document/container[@classes='toc-even-footer']">
                <xsl:text>odd-even</xsl:text>
            </xsl:when>
            <xsl:otherwise>
                <xsl:text>simple</xsl:text>
            </xsl:otherwise>
        </xsl:choose>
    </xsl:variable>

    <xsl:template name="my-boolean-func">
        <xsl:param name="string"/>
        <xsl:param name="name"/>
        <xsl:param name="allow-empty-string" select="boolean('true')"/>
        <xsl:choose>
            <xsl:when test="$string = '' and $allow-empty-string">
                <xsl:value-of select= "boolean('')"/>
            </xsl:when>
            <xsl:when test="$string = 'yes' or $string = 'Yes' or $string = 'true' or $string = 'True'">
                <xsl:value-of select= "boolean('true')"/>
            </xsl:when>
            <xsl:when test="$string = 'no' or $string = 'No' or $string = 'false' or $string = 'False'">
                <xsl:value-of select= "boolean('')"/>
            </xsl:when>
            <xsl:otherwise>
                <xsl:variable name="msg">
                    <xsl:text>"</xsl:text>
                    <xsl:value-of select="$string"/>
                    <xsl:text>"</xsl:text>
                    <xsl:text> not a valid boolean value for </xsl:text>
                    <xsl:value-of select="$name"/>
                    <xsl:text>&#xA;</xsl:text>
                </xsl:variable>
                <xsl:call-template name="quit-message">
                    <xsl:with-param name="msg" select="$msg"/>
                </xsl:call-template>
            </xsl:otherwise>
        </xsl:choose>
    </xsl:template>

    <xsl:variable name="custom-spc-header-footer">
        <xsl:call-template name="my-boolean-func">
            <xsl:with-param name="string" select="$custom-spacing-header-footer"/>
            <xsl:with-param name="name" select="'custom-spacing-header-footer'"/>
        </xsl:call-template>
    </xsl:variable>

    
</xsl:stylesheet>