transformation2.xsl 10.4 KB
Newer Older
1 2 3 4 5 6 7 8
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:h="http://www.utc.fr/ics/hdoc/xhtml"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0"
    xmlns:sc="http://www.utc.fr/ics/scenari/v3/core" xmlns:cp="canope.fr:canoprof"
    xmlns:sp="http://www.utc.fr/ics/scenari/v3/primitive"
    xmlns:fn="http://www.w3.org/2005/xpath-functions" xmlns:xs="http://www.w3.org/2001/XMLSchema"
    exclude-result-prefixes="xs">
    <xsl:output method="xml" indent="yes" encoding="UTF-8"/>
Benoit Villain's avatar
Benoit Villain committed
9
    
10
    <xsl:param name="filename"/>
Benoit Villain's avatar
Benoit Villain committed
11
    
12
    <xsl:strip-space elements="*"/>
Benoit Villain's avatar
Benoit Villain committed
13
    
14 15 16 17 18 19 20 21 22
    <!-- This template matches the root. One hdoc file = one Canoprof's Programme" -->
    <xsl:template match="h:html">
        <sc:item xmlns:sc="http://www.utc.fr/ics/scenari/v3/core">
            <cp:program xmlns:cp="canope.fr:canoprof"
                xmlns:sp="http://www.utc.fr/ics/scenari/v3/primitive">
                <xsl:apply-templates select="./*"/>
            </cp:program>
        </sc:item>
    </xsl:template>
Benoit Villain's avatar
Benoit Villain committed
23
    
24 25 26 27 28 29 30
    <!-- Head related templates. -->
    <xsl:template match="h:head">
        <cp:programM>
            <!-- Title of Programme. -->
            <sp:title>
                <xsl:value-of select="./h:title"/>
            </sp:title>
Benoit Villain's avatar
Benoit Villain committed
31
            
32 33
            <!-- Hdoc's "date" = Programme's period. -->
            <xsl:apply-templates select="./h:meta[@name='date']"/>
Benoit Villain's avatar
Benoit Villain committed
34
            
35 36
            <!-- Hdoc's "description" = Programme's resume. -->
            <xsl:apply-templates select="./h:meta[@name='description']"/>
Benoit Villain's avatar
Benoit Villain committed
37
            
38 39
        </cp:programM>
    </xsl:template>
Benoit Villain's avatar
Benoit Villain committed
40
    
41 42 43 44 45
    <xsl:template match="h:head/h:meta[@name='date']">
        <sp:period>
            <xsl:value-of select="./@content"/>
        </sp:period>
    </xsl:template>
Benoit Villain's avatar
Benoit Villain committed
46
    
47 48 49 50 51 52 53 54 55 56
    <xsl:template match="h:head/h:meta[@name='description']">
        <sp:abstract>
            <cp:txtDesc>
                <sc:para xml:space="preserve">
                    <xsl:value-of select="./@content"/>
                </sc:para>
            </cp:txtDesc>
        </sp:abstract>
    </xsl:template>
    
Benoit Villain's avatar
Benoit Villain committed
57
    
58 59 60 61 62 63 64 65 66 67 68 69
    <!-- Body related templates. -->
    <xsl:template match="h:body">
        <xsl:if test="./*">
            <xsl:apply-templates select="./*"/>
        </xsl:if>
    </xsl:template>
    
    <!-- Section related templates -->
    <!-- CanoProf's Seance = hdoc's  body/Section = Opale's Division -->
    <!-- CanoProf's Activite TetM = hdoc's  body/Section/Section = Opale's Grain -->
    <!-- CanoProf's Activite TetM (section) = hdoc's  body/Section/Section/(Section...) = Opale's Grain (partie) -->
    
Benoit Villain's avatar
Benoit Villain committed
70
    <!-- CanoProf's Seance = hdoc's  body/Section = Opale's Division or Activite-->
71
    <xsl:template match="h:body/h:section">
Benoit Villain's avatar
Benoit Villain committed
72 73 74 75 76 77 78 79 80 81 82 83 84
        <xsl:if test="./*">
            <sp:session>
                <cp:session>
                    <cp:sessionM>
                        <sp:title>
                            <xsl:if test="not(./h:header/h:h1/text())"> Untitled </xsl:if>
                            <xsl:value-of select="./h:header/h:h1"/>
                        </sp:title>
                    </cp:sessionM>
                    <xsl:apply-templates select="./*"/>
                </cp:session>
            </sp:session>
        </xsl:if>
85 86
    </xsl:template>
    
Benoit Villain's avatar
Benoit Villain committed
87
    <!-- if Section have only a dev (no sub section), we create a short activty to print text into a seance -->
88
    <xsl:template match="h:body/h:section/h:div">
Benoit Villain's avatar
Benoit Villain committed
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
        <sp:shortActivity>
            <cp:shortActivity>
                <cp:activityM>
                    <sp:title>
                        <xsl:value-of select="../h:header/h:h1"/>
                    </sp:title>
                </cp:activityM>
                <sp:body>
                    <cp:flow>
                        <xsl:apply-templates select="./*"/>
                    </cp:flow>
                </sp:body>
            </cp:shortActivity>
        </sp:shortActivity>
    </xsl:template>
    
    <!-- Toutes les introductions de sections sont transformés en résumé. -->
    <xsl:template match="h:header/h:div[@data-hdoc-type = 'introduction']">
        <sp:abstract>
            <cp:txtDesc>
                <sc:para xml:space="preserve">
                    <xsl:value-of select="./text()"/>
                </sc:para>
            </cp:txtDesc>
        </sp:abstract>
    </xsl:template>
    
    <!-- Text related templates -->
    <xsl:template match="h:p | h:ul | h:ol">
        <xsl:if test="not(preceding-sibling::h:p)">
            <xsl:if test="not(preceding-sibling::h:ul)">
                <xsl:if test="not(preceding-sibling::h:ol)">
                    <xsl:choose>
                        
                        <!-- If it is directly included in a div, we have to add Canoprof's text markups -->
                        <xsl:when test="parent::*[name() = 'div']">
                            <sp:txt>
                                <cp:txt>
                                    <xsl:call-template name="blockloop"/>
                                </cp:txt>
                            </sp:txt>
                        </xsl:when>
                        
                        <!-- Otherwise, we can directly display it (this can happen when it is included within a list or a table) -->
                        <xsl:otherwise>
                            <xsl:call-template name="blockloop"/>
                        </xsl:otherwise>
                    </xsl:choose>
                </xsl:if>
            </xsl:if>
        </xsl:if>
    </xsl:template>
    
    <xsl:template name="blockloop">
        <xsl:for-each select=". | ./following-sibling::*">
            <xsl:choose>
                
                <!-- Paragraph -->
                <xsl:when test="name() = 'p' and (./* | ./text())">
                    <sc:para xml:space="preserve">
                        <xsl:apply-templates select="./* | ./text()"/>
                    </sc:para>
                </xsl:when>
                
                <!-- Unordered list -->
                <xsl:when test="name() = 'ul' and (./h:li/h:p/text())">
                    <sc:itemizedList>
                        <xsl:apply-templates select="./* | ./text()"/>
                    </sc:itemizedList>
                </xsl:when>
                
                <!-- Ordered list -->
                <xsl:when test="name() = 'ol' and (./h:li/h:p/text())">
                    <sc:orderedList>
                        <xsl:apply-templates select="./* | ./text()"/>
                    </sc:orderedList>
                </xsl:when>
                
            </xsl:choose>
        </xsl:for-each>
169 170
    </xsl:template>
    
Benoit Villain's avatar
Benoit Villain committed
171 172 173 174
    <xsl:template match="h:li">
        <sc:listItem>
            <xsl:apply-templates select="./* | ./text()"/>
        </sc:listItem>
175
    </xsl:template>
Benoit Villain's avatar
Benoit Villain committed
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 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281
    
    <xsl:template match="h:i">
        <xsl:if test="./* | ./text()">
            <sc:inlineStyle role="specific">
                <xsl:apply-templates select="./* | ./text()"/>
            </sc:inlineStyle>
        </xsl:if>
    </xsl:template>
    <xsl:template match="h:em">
        <xsl:if test="./* | ./text()">
            <sc:inlineStyle role="emphasis">
                <xsl:apply-templates select="./* | ./text()"/>
            </sc:inlineStyle>
        </xsl:if>
    </xsl:template>
    <xsl:template match="h:q">
        <xsl:if test="./* | ./text()">
            <sc:phrase role="quote">
                <xsl:apply-templates select="./* | ./text()"/>
            </sc:phrase>
        </xsl:if>
    </xsl:template>
    <xsl:template match="h:sub">
        <xsl:if test="./* | ./text()">
            <sc:textLeaf role="ind">
                <xsl:apply-templates select="./* | ./text()"/>
            </sc:textLeaf>
        </xsl:if>
    </xsl:template>
    <xsl:template match="h:sup">
        <xsl:if test="./* | ./text()">
            <sc:textLeaf role="exp">
                <xsl:apply-templates select="./* | ./text()"/>
            </sc:textLeaf>
        </xsl:if>
    </xsl:template>
    <xsl:template match="h:a">
        <xsl:if test="./* | ./text()">
            <sc:phrase role="url">
                <cp:link xmlns:sc="http://www.utc.fr/ics/scenari/v3/core"
                    xmlns:cp="canope.fr:canoprof"
                    xmlns:sp="http://www.utc.fr/ics/scenari/v3/primitive">
                    <sp:url>
                        <xsl:value-of select="./@href"/>
                    </sp:url>
                </cp:link>
                <xsl:if test="./@title">
                    <sp:title>
                        <xsl:value-of select="./@title"/>
                    </sp:title>
                </xsl:if>
                <xsl:value-of select="."/>
            </sc:phrase>
        </xsl:if>
    </xsl:template>
    
    <!-- Table related templates -->
    <xsl:template match="h:table">
        <xsl:choose>
            <xsl:when test="parent::*[name() = 'div']">
                <!-- If this <table> is a direct child of a <div> then it must be surrounded by Opale's text markups. -->
                <sp:txt>
                    <cp:txt>
                        <sc:table>
                            <xsl:if test="./h:caption">
                                <sc:caption>
                                    <xsl:value-of select="./h:caption"/>
                                </sc:caption>
                            </xsl:if>
                            <xsl:apply-templates select="./h:tr"/>
                        </sc:table>
                    </cp:txt>
                </sp:txt>
            </xsl:when>
            <xsl:otherwise>
                <sc:table>
                    <xsl:if test="./h:caption">
                        <sc:caption>
                            <xsl:value-of select="./h:caption"/>
                        </sc:caption>
                    </xsl:if>
                    <xsl:apply-templates select="./h:tr"/>
                </sc:table>
            </xsl:otherwise>
        </xsl:choose>
    </xsl:template>
    
    <xsl:template match="h:tr">
        <sc:row>
            <xsl:apply-templates select="./h:td"/>
        </sc:row>
    </xsl:template>
    
    <xsl:template match="h:td">
        <sc:cell>
            <xsl:apply-templates select="./*"/>
        </sc:cell>
    </xsl:template>
    
    <xsl:template match="h:header"/>
    <!-- Its content is already used in <xsl:template match="h:section"> -->
    <xsl:template match="h:h6"/>
    <!-- Its content is already used in <xsl:template match="h:div"> -->
    <xsl:template match="h:h1"/>
    <!-- Its content is already used in <xsl:template match="h:section"> -->
    
282
</xsl:stylesheet>