transformation2.xsl 19.6 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
        <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>
    
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 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 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325
    <!-- CanoProf's Activite TetM = hdoc's  body/Section/Section = Opale's Grain -->
    <xsl:template match="h:body/h:section/h:section">
        <xsl:if test="./*">
            <sp:textActivity>
                <cp:textActivity>
                    <cp:activityM>
                        <sp:title>
                            <xsl:if test="not(./h:header/h:h1/text())"> Untitled </xsl:if>
                            <xsl:value-of select="./h:header/h:h1"/>
                        </sp:title>
                        <xsl:if test="(./h:header/h:div[@data-hdoc-type = 'introduction']/text())">
                            <xsl:apply-templates
                                select="./h:header/h:div[@data-hdoc-type = 'introduction']"/>
                        </xsl:if>
                    </cp:activityM>
                    <xsl:if test="./h:div/*">
                        <sp:body>
                            <cp:blocks>
                                <xsl:apply-templates select="./h:div"/>
                            </cp:blocks>
                        </sp:body>
                    </xsl:if>
                    <xsl:if test="./h:section/*">
                        <xsl:apply-templates select="./h:section" mode="CanoprofSection"/>
                    </xsl:if>
                </cp:textActivity>
            </sp:textActivity>
        </xsl:if>
    </xsl:template>
    
    <!-- CanoProf's Activite TetM (section) = hdoc's  body/Section/Section/(Section...) = Opale's Grain (partie) -->
    <!-- TODO -->
    <xsl:template match="h:section" mode="CanoprofSection">
    </xsl:template>
    
    <!-- Div related templates -->
    <!-- Formatting content based on @data-hdoc-type -->
    <xsl:template match="h:div">
        <xsl:choose>
            <!-- hdoc's explanation = canoprof's information (NOT EXPLICIT...) -->
            <xsl:when test="./@data-hdoc-type = 'explanation'">
                <sp:info>
                    <cp:block>
                        <xsl:if test="string-length(./h:h6/text()) > 0">
                            <cp:blockM>
                                <sp:title>
                                    <xsl:value-of select="./h:h6"/>
                                </sp:title>
                            </cp:blockM>
                        </xsl:if>
                        <sp:body>
                            <cp:flow>
                                <xsl:apply-templates select="./*"/>
                            </cp:flow>
                        </sp:body>
                    </cp:block>
                </sp:info>
            </xsl:when>
            <!-- hdoc's warning = canoprof's warning -->
            <xsl:when test="./@data-hdoc-type = 'warning'">
                <sp:warning>
                    <cp:block>
                        <cp:blockM>
                            <xsl:if test="string-length(./h:h6/text()) > 0">
                                <sp:title>
                                    <xsl:value-of select="./h:h6"/>
                                </sp:title>
                            </xsl:if>
                        </cp:blockM>
                        <sp:body>
                            <cp:flow>
                                <xsl:apply-templates select="./*"/>
                            </cp:flow>
                        </sp:body>
                    </cp:block>
                </sp:warning>
            </xsl:when>
            <!-- hdoc's complement = canoprof's complement (extra) -->
            <xsl:when test="./@data-hdoc-type = 'complement'">
                <sp:extra>
                    <cp:block>
                        <cp:blockM>
                            <xsl:if test="string-length(./h:h6/text()) > 0">
                                <sp:title>
                                    <xsl:value-of select="./h:h6"/>
                                </sp:title>
                            </xsl:if>
                        </cp:blockM>
                        <sp:body>
                            <cp:flow>
                                <xsl:apply-templates select="./*"/>
                            </cp:flow>
                        </sp:body>
                    </cp:block>
                </sp:extra>
            </xsl:when>
            <!-- hdoc's advice = canoprof's advice -->
            <xsl:when test="./@data-hdoc-type = 'advice'">
                <sp:advice>
                    <cp:block>
                        <cp:blockM>
                            <xsl:if test="string-length(./h:h6/text()) > 0">
                                <sp:title>
                                    <xsl:value-of select="./h:h6"/>
                                </sp:title>
                            </xsl:if>
                        </cp:blockM>
                        <sp:body>
                            <cp:flow>
                                <xsl:apply-templates select="./*"/>
                            </cp:flow>
                        </sp:body>
                    </cp:block>
                </sp:advice>
            </xsl:when>
            <!-- hdoc's definition = canoprof's definition -->
            <xsl:when test="./@data-hdoc-type = 'definition'">
                <sp:definition>
                    <cp:block>
                        <cp:blockM>
                            <xsl:if test="string-length(./h:h6/text()) > 0">
                                <sp:title>
                                    <xsl:value-of select="./h:h6"/>
                                </sp:title>
                            </xsl:if>
                        </cp:blockM>
                        <sp:body>
                            <cp:flow>
                                <xsl:apply-templates select="./*"/>
                            </cp:flow>
                        </sp:body>
                    </cp:block>
                </sp:definition>
            </xsl:when>
            <!-- hdoc's example = canoprof's example -->
            <xsl:when test="./@data-hdoc-type = 'example'">
                <sp:example>
                    <cp:block>
                        <cp:blockM>
                            <xsl:if test="string-length(./h:h6/text()) > 0">
                                <sp:title>
                                    <xsl:value-of select="./h:h6"/>
                                </sp:title>
                            </xsl:if>
                        </cp:blockM>
                        <sp:body>
                            <cp:flow>
                                <xsl:apply-templates select="./*"/>
                            </cp:flow>
                        </sp:body>
                    </cp:block>
                </sp:example>
            </xsl:when>
            <!-- hdoc's remark = canoprof's hypothesis (NOT EXPLICIT...) -->
            <xsl:when test="./@data-hdoc-type = 'remark'">
                <sp:hypothesis>
                    <cp:block>
                        <cp:blockM>
                            <xsl:if test="string-length(./h:h6/text()) > 0">
                                <sp:title>
                                    <xsl:value-of select="./h:h6"/>
                                </sp:title>
                            </xsl:if>
                        </cp:blockM>
                        <sp:body>
                            <cp:flow>
                                <xsl:apply-templates select="./*"/>
                            </cp:flow>
                        </sp:body>
                    </cp:block>
                </sp:hypothesis>
            </xsl:when>
            <!-- hdoc's emphasis = canoprof's method (NOT EXPLICIT...) -->
            <xsl:when test="./@data-hdoc-type = 'emphasis'">
                <sp:method>
                    <cp:block>
                        <cp:blockM>
                            <xsl:if test="string-length(./h:h6/text()) > 0">
                                <sp:title>
                                    <xsl:value-of select="./h:h6"/>
                                </sp:title>
                            </xsl:if>
                        </cp:blockM>
                        <sp:body>
                            <cp:flow>
                                <xsl:apply-templates select="./*"/>
                            </cp:flow>
                        </sp:body>
                    </cp:block>
                </sp:method>
            </xsl:when>
            <!-- hdoc's autres or no attribute = canoprof's information-->
            <xsl:otherwise>
                <sp:info>
                    <cp:block>
                        <xsl:if test="string-length(./h:h6/text()) > 0">
                            <cp:blockM>
                                <sp:title>
                                    <xsl:value-of select="./h:h6"/>
                                </sp:title>
                            </cp:blockM>
                        </xsl:if>
                        <sp:body>
                            <cp:flow>
                                <xsl:apply-templates select="./*"/>
                            </cp:flow>
                        </sp:body>
                    </cp:block>
                </sp:info>
                <!--                
326 327
                <sp:body>
                    <cp:flow>
328
                        <xsl:apply-templates select="./*"/>
329 330
                    </cp:flow>
                </sp:body>
331 332 333
-->
            </xsl:otherwise>
        </xsl:choose>
334 335
    </xsl:template>
    
Benoit Villain's avatar
Benoit Villain committed
336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388
    <!-- 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>
389 390
    </xsl:template>
    
Benoit Villain's avatar
Benoit Villain committed
391 392 393 394
    <xsl:template match="h:li">
        <sc:listItem>
            <xsl:apply-templates select="./* | ./text()"/>
        </sc:listItem>
395
    </xsl:template>
Benoit Villain's avatar
Benoit Villain committed
396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501
    
    <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"> -->
    
502
</xsl:stylesheet>