transformation2.xsl 32 KB
Newer Older
1 2 3
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet
  xmlns:h="http://www.utc.fr/ics/hdoc/xhtml"
4
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0"
5 6 7
  xmlns:sc="http://www.utc.fr/ics/scenari/v3/core"
  xmlns:op="utc.fr:ics/opale3"
  xmlns:sp="http://www.utc.fr/ics/scenari/v3/primitive"
8
  xmlns:fn="http://www.w3.org/2005/xpath-functions"
9 10
  xmlns:xs="http://www.w3.org/2001/XMLSchema" 
  exclude-result-prefixes="xs"
11 12 13
  >
  <xsl:output method="xml" indent="yes" encoding="UTF-8"/>
  
14 15
  <xsl:param name="filename"/>
  
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
  <!-- This template matches the root. One hdoc file = one Opale's "Module" -->
    <xsl:template match="h:html">
    <sc:item xmlns:sc="http://www.utc.fr/ics/scenari/v3/core">
      <op:ue xmlns:sp="http://www.utc.fr/ics/scenari/v3/primitive" xmlns:op="utc.fr:ics/opale3" xmlns:sc="http://www.utc.fr/ics/scenari/v3/core">
        <xsl:apply-templates select="./*"/>
      </op:ue>
    </sc:item>
  </xsl:template>

  <!-- Head related templates. -->
    <xsl:template match="h:head">
      <op:ueM xmlns:sp="http://www.utc.fr/ics/scenari/v3/primitive" xmlns:op="utc.fr:ics/opale3" xmlns:sc="http://www.utc.fr/ics/scenari/v3/core">
        <sp:title>
          <xsl:value-of select="./h:title"/>
        </sp:title>
        <sp:info>
          <op:info>
33 34 35 36 37 38
            <sp:keywds>
              <op:keywds>
                <xsl:apply-templates select="//h:meta[@name='keywords']"/> <!-- Keywords tag is processed separatly -->
              </op:keywds>
            </sp:keywds>
            <xsl:apply-templates select="./h:meta[@name != 'keywords']"/>
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

            <!-- Author: in case several authors are specified, we don't want to get an error for not respecting the schema -->
            <xsl:if test="./h:meta[@name='author']">
              <sp:cpyrgt>
                <op:sPara>
                  <sc:para>
                    <xsl:call-template name="join">
                        <xsl:with-param name="list" select="./h:meta[@name='author']/@content" />
                        <xsl:with-param name="separator" select="', '" />
                    </xsl:call-template>
                  </sc:para>
                </op:sPara>
              </sp:cpyrgt>
            </xsl:if>

          </op:info>
        </sp:info>
      </op:ueM>
    </xsl:template>

    <!-- Join template found at http://stackoverflow.com/questions/12585974/xslt-merging-concatinating-values-of-siblings-nodes-of-same-name-into-single-nod -->
    <xsl:template name="join">
        <xsl:param name="list" />
        <xsl:param name="separator"/>

        <xsl:for-each select="$list">
            <xsl:value-of select="." />
            <xsl:if test="position() != last()">
                <xsl:value-of select="$separator" />
            </xsl:if>
        </xsl:for-each>
    </xsl:template>
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86
  
  <!-- 
    The keywords tag is processed separatly 
    because according to the Hdoc Rng schema
    there might be multiple <meta name="keywords" tags
    
    This allow us to treat all the different tags 
    and merge them according to Opale schema
  -->
  <xsl:template match="h:meta[@name='keywords']" priority="1">
      <xsl:for-each select="fn:tokenize(./@content,',')">
        <sp:keywd>
          <xsl:value-of select="normalize-space(.)"/>
        </sp:keywd>
      </xsl:for-each>
    </xsl:template>
87 88 89 90

    <xsl:template match="h:meta[@name]">
    <xsl:choose>
      <xsl:when test="./@name = 'description'"/> <!-- Unsupported : Opale doesn't provide any description metadata. -->
91
      <xsl:when test="./@name = 'keywords'"/> <!-- Done above -->
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113
      <xsl:when test="./@name = 'author'"/> <!-- Done above -->
      <xsl:when test="./@name = 'rights'">
        <xsl:choose>
          <xsl:when test="./@content = 'http://creativecommons.org/publicdomain/zero/1.0/deed.en'"><sp:cc>zero</sp:cc></xsl:when>
          <xsl:when test="./@content = 'Public Domain'"><sp:cc>publicdomain</sp:cc></xsl:when>
          <xsl:when test="./@content = 'http://www.gnu.org/licenses/gpl.html'"><sp:cc>gnu-fdl</sp:cc></xsl:when>
          <xsl:when test="./@content = 'http://creativecommons.org/licenses/by/4.0/deed.en'"><sp:cc>by</sp:cc></xsl:when>
          <xsl:when test="./@content = 'http://creativecommons.org/licenses/by-sa/4.0/deed.en'"><sp:cc>by-sa</sp:cc></xsl:when>
          <xsl:when test="./@content = 'http://creativecommons.org/licenses/by-nd/4.0/deed.en'"><sp:cc>by-nd</sp:cc></xsl:when>
          <xsl:when test="./@content = 'http://creativecommons.org/licenses/by-nc/4.0/deed.en'"><sp:cc>by-nc</sp:cc></xsl:when>
          <xsl:when test="./@content = 'http://creativecommons.org/licenses/by-nc-sa/4.0/deed.en'"><sp:cc>by-nc-sa</sp:cc></xsl:when>
          <xsl:when test="./@content = 'http://creativecommons.org/licenses/by-nc-nd/4.0/deed.en'"><sp:cc>by-nc-nd</sp:cc></xsl:when>
    		  <xsl:otherwise/> <!-- This previous list is supposed to support every possible case, any other value for "rights" are unsupported. -->
        </xsl:choose>
      </xsl:when>
      <xsl:when test="./@name = 'date'"/> <!-- Unsupported : Opale doesn't provide any date metadata. -->
      <xsl:otherwise/> <!-- There are no other values for ./@name right now. -->
    </xsl:choose>
  </xsl:template>

  <!-- Body related templates. -->
    <xsl:template match="h:body">
Anna Lainé's avatar
Anna Lainé committed
114
      <xsl:if test="./h:section[@data-hdoc-type = 'introduction']/h:div/*">
115 116
        <sp:intro>
          <op:res>
Anna Lainé's avatar
Anna Lainé committed
117
             <xsl:apply-templates select="./h:section[@data-hdoc-type = 'introduction']/h:div/*" />
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
          </op:res>
        </sp:intro>
      </xsl:if>

      <!-- In case an introduction contains subsections, we consider them as regular sections outside from it -->
      <xsl:apply-templates select="./h:section[@data-hdoc-type = 'introduction']/h:section"/>

      <!-- Not selecting introductions or conclusions -->
      <xsl:apply-templates select="./h:section[not(@data-hdoc-type = 'introduction' or @data-hdoc-type = 'conclusion')]"/>

      <!-- Same thing as for the introduction -->
      <xsl:apply-templates select="./h:section[@data-hdoc-type = 'conclusion']/h:section"/>

      <xsl:if test="./h:section[@data-hdoc-type = 'conclusion']/h:div/*">
        <sp:conclu>
          <op:res>
            <xsl:apply-templates select="./h:section[@data-hdoc-type = 'conclusion']/h:div/*" />
          </op:res>
        </sp:conclu>
      </xsl:if>
    </xsl:template>

    <!-- Introduction <section> -->
    <xsl:template match="h:div[@data-hdoc-type='introduction']">
      <sp:intro>
        <op:res>
144 145 146 147 148 149
          <sp:txt>
            <op:txt>
            <sc:para>
              <xsl:apply-templates select="./text()" /></sc:para>
            </op:txt>
          </sp:txt>
150 151 152 153 154
        </op:res>
      </sp:intro>
    </xsl:template>

    <!-- Conclusion <section> -->
155
    <xsl:template match="h:footer/h:div[@data-hdoc-type='conclusion']">
156 157
      <sp:conclu>
        <op:res>
158 159 160 161 162 163 164 165 166
          <sp:txt>
            <op:txt>
              <sc:para>
                <!-- Going straight to the content -->
                <!-- For the conclusion, we ignore <header> and <footer> -->
                <xsl:apply-templates select="./text()" />
              </sc:para>
            </op:txt>
          </sp:txt>
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
        </op:res>
      </sp:conclu>
    </xsl:template>

    <!-- Grains <sections>. A grain is either a unit-of-content, or does not contain sub divisions (<section>'s) -->
    <xsl:template match="h:section[@data-hdoc-type='unit-of-content' or h:div or not(h:section)]">
      <sp:courseUc>
        <op:expUc>
          <op:uM>
            <sp:title>
              <!-- Adding a default value for titles (Opale requires a title to be specified) -->
              <xsl:if test="not(./h:header/h:h1/text())">
                Untitled
              </xsl:if>
              <xsl:value-of select="./h:header/h:h1"/>
            </sp:title>
          </op:uM>

          <!-- TODO test level of sub division (section/section/section) -->
          <xsl:if test="./h:div">
            <sp:pb>
              <op:pb>
                <xsl:apply-templates select="./h:div"/>
              </op:pb>
            </sp:pb>
          </xsl:if>

          <!-- Applying sub sections -->
          <xsl:apply-templates select="./h:section" mode="under-unit-of-content" />
        </op:expUc>
      </sp:courseUc>
    </xsl:template>

    <xsl:template match="h:section" mode="under-unit-of-content">
      <sp:div>
        <op:expUcDiv>
          <op:expUcDivM>
            <sp:title>
              <!-- Adding a default value for titles (Opale requires a title to be specified) -->
              <xsl:if test="not(./h:header/h:h1/text())">
                Untitled
              </xsl:if>

              <xsl:value-of select="./h:header/h:h1"/>
            </sp:title>
          </op:expUcDivM>

          <!-- TODO test level of sub division (section/section/section) -->
          <xsl:if test="./h:div">
            <sp:pb>
              <op:pb>
                <xsl:apply-templates select="./h:div"/>
              </op:pb>
            </sp:pb>
          </xsl:if>

          <xsl:apply-templates select="./h:section" mode="under-unit-of-content" />
        </op:expUcDiv>
      </sp:div>
    </xsl:template>

    <!-- Basic <section> (nothing was specified) -->
    <xsl:template match="h:section">
      <!-- Every section is converted into what Opale calls a "Division" -->
      <!-- For now there are no specific processes applied on sections with an "introduction" or "conclusion" value in their data-hdoc-type attribute.
      They are processed the same as standard sections.
      -->
      <sp:div>
        <op:ueDiv>
          <op:ueDivM>
            <sp:title>
              <xsl:value-of select="./h:header/h:h1"/>
            </sp:title>
          </op:ueDivM>

          <!-- Intro for a division -->
          <xsl:apply-templates select="./h:header/h:div[@data-hdoc-type='introduction']" />

          <!-- Taking care of the content. If content exists, we add it as a "grain" (we also add a title to it) -->
          <xsl:if test="./h:div">
            <sp:courseUc>
              <op:expUc>
                <op:uM>
                  <xsl:if test="./h:header/h:h1">
                    <sp:title>
                      <xsl:value-of select="./h:header/h:h1"/>
                    </sp:title>
                  </xsl:if>
                </op:uM>

                <xsl:if test="./h:div">
                  <sp:pb>
                    <op:pb>
                      <xsl:apply-templates select="./h:div"/>
                    </op:pb>
                  </sp:pb>
                </xsl:if>
              </op:expUc>
            </sp:courseUc>
          </xsl:if>

          <!-- Applying templates to section that are neither an introduction nor a conclusion -->
          <xsl:apply-templates select="./h:section[not(@data-hdoc-type = 'introduction' or @data-hdoc-type = 'conclusion')]"/>

          <!-- Conclusion for a division -->
272
          <xsl:apply-templates select="./h:footer/h:div[@data-hdoc-type='conclusion']" />
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 326 327 328 329 330 331 332 333 334 335 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

        </op:ueDiv>
      </sp:div>
    </xsl:template>

    <!-- Formatting content based on @data-hdoc-type -->
    <xsl:template match="h:div">
    <xsl:choose>
      <xsl:when test="./@data-hdoc-type = 'emphasis'">
        <sp:basic>
          <op:pbTi>
            <xsl:if test="string-length(./h:h6/text()) > 0">
              <sp:title>
                <xsl:value-of select="./h:h6"/>
              </sp:title>
            </xsl:if>
          </op:pbTi>
          <op:res>
            <xsl:apply-templates select="./*"/>
          </op:res>
        </sp:basic>
      </xsl:when>
      <xsl:when test="./@data-hdoc-type = 'complement'">
        <sp:comp>
          <op:pbTi>
            <xsl:if test="string-length(./h:h6/text()) > 0">
              <sp:title>
                <xsl:value-of select="./h:h6"/>
              </sp:title>
            </xsl:if>
          </op:pbTi>
          <op:res>
            <xsl:apply-templates select="./*"/>
          </op:res>
        </sp:comp>
      </xsl:when>
      <xsl:when test="./@data-hdoc-type = 'definition'">
        <sp:def>
          <op:pbTi>
            <xsl:if test="string-length(./h:h6/text()) > 0">
              <sp:title>
                <xsl:value-of select="./h:h6"/>
              </sp:title>
            </xsl:if>
          </op:pbTi>
          <op:res>
            <xsl:apply-templates select="./*"/>
          </op:res>
        </sp:def>
      </xsl:when>
      <xsl:when test="./@data-hdoc-type = 'example'">
        <sp:ex>
          <op:pbTi>
            <xsl:if test="string-length(./h:h6/text()) > 0">
              <sp:title>
                <xsl:value-of select="./h:h6"/>
              </sp:title>
            </xsl:if>
          </op:pbTi>
          <op:res>
            <xsl:apply-templates select="./*"/>
          </op:res>
        </sp:ex>
      </xsl:when>
      <xsl:when test="./@data-hdoc-type = 'remark'">
        <sp:rem>
          <op:pbTi>
            <xsl:if test="string-length(./h:h6/text()) > 0">
              <sp:title>
                <xsl:value-of select="./h:h6"/>
              </sp:title>
            </xsl:if>
          </op:pbTi>
          <op:res>
            <xsl:apply-templates select="./*"/>
          </op:res>
        </sp:rem>
      </xsl:when>
      <xsl:when test="./@data-hdoc-type = 'warning'">
        <sp:warning>
          <op:pbTi>
            <xsl:if test="string-length(./h:h6/text()) > 0">
              <sp:title>
                <xsl:value-of select="./h:h6"/>
              </sp:title>
            </xsl:if>
          </op:pbTi>
          <op:res>
            <xsl:apply-templates select="./*"/>
          </op:res>
        </sp:warning>
      </xsl:when>
      <xsl:when test="./@data-hdoc-type = 'advice'">
        <sp:adv>
          <op:pbTi>
            <xsl:if test="string-length(./h:h6/text()) > 0">
              <sp:title>
                <xsl:value-of select="./h:h6"/>
              </sp:title>
            </xsl:if>
          </op:pbTi>
          <op:res>
            <xsl:apply-templates select="./*"/>
          </op:res>
        </sp:adv>
      </xsl:when>
379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406
      <xsl:when test="./@data-hdoc-type = 'method'">
        <sp:meth>
          <op:pbTi>
            <xsl:if test="string-length(./h:h6/text()) > 0">
              <sp:title>
                <xsl:value-of select="./h:h6"/>
              </sp:title>
            </xsl:if>
          </op:pbTi>
          <op:res>
            <xsl:apply-templates select="./*"/>
          </op:res>
        </sp:meth>
      </xsl:when>
      <xsl:when test="./@data-hdoc-type = 'remind'">
        <sp:remind>
          <op:pbTi>
            <xsl:if test="string-length(./h:h6/text()) > 0">
              <sp:title>
                <xsl:value-of select="./h:h6"/>
              </sp:title>
            </xsl:if>
          </op:pbTi>
          <op:res>
            <xsl:apply-templates select="./*"/>
          </op:res>
        </sp:remind>
      </xsl:when>
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
      <xsl:otherwise>
        <sp:info>
          <op:pbTi>
            <xsl:if test="string-length(./h:h6/text()) > 0">
              <sp:title>
                <xsl:value-of select="./h:h6"/>
              </sp:title>
            </xsl:if>
          </op:pbTi>
          <op:res>
            <xsl:apply-templates select="./*"/>
          </op:res>
        </sp:info>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>
  
  <!-- Section related templates. -->
  <xsl:template match="h:footer/h:div[@data-hdoc-type = 'tags']">
    <sp:keywd><xsl:value-of select="./h:span"/></sp:keywd>
  </xsl:template>
  
  <!-- Div related templates. -->
    <!-- Text related templates -->

    <!-- This template is a little peculiar: the idea is to match the first block and then to call a loop on it and its siblings -->
    <!-- This is to avoid having several text blocks for the same <div> -->
    <!-- This could be handled at the div level -->
      <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 Opale's text markups -->
442
                <xsl:when test="(parent::*[name() = 'div'] or parent::*[name() = 'span']) and not(parent::*[@data-hdoc-type = 'gapText']) and not(parent::*[@data-hdoc-type = 'label']) and not(parent::*[@data-hdoc-type = 'target'])">
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 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618
                  <sp:txt>
                    <op:txt>
                      <xsl:call-template name="blockloop"/>
                    </op: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'">
              <sc:para>
                <xsl:apply-templates select="./* | ./text()"/>
              </sc:para>
            </xsl:when>

            <!-- Unordered list -->
            <xsl:when test="name() = 'ul'">
              <sc:itemizedList>
                <xsl:apply-templates select="./* | ./text()"/>
              </sc:itemizedList>
            </xsl:when>

            <!-- Ordered list -->
            <xsl:when test="name() = 'ol'">
              <sc:orderedList>
                <xsl:apply-templates select="./* | ./text()"/>
              </sc:orderedList>
            </xsl:when>

          </xsl:choose>
        </xsl:for-each>
      </xsl:template>

      <!-- These templates are made to avoid matching text block elements that are not the first ones -->
      <!--<xsl:template match="h:p"/>
      <xsl:template match="h:ul"/>
      <xsl:template match="h:ol"/>-->

      <xsl:template match="h:i">
        <sc:inlineStyle role="spec">
          <xsl:apply-templates select="./* | ./text()"/>
        </sc:inlineStyle>
      </xsl:template>
      <xsl:template match="h:em">
        <sc:inlineStyle role="emp">
          <xsl:apply-templates select="./* | ./text()"/>
        </sc:inlineStyle>
      </xsl:template>
      <xsl:template match="h:q">
        <sc:inlineStyle role="quote">
          <xsl:apply-templates select="./* | ./text()"/>
        </sc:inlineStyle>
      </xsl:template>
      <xsl:template match="h:sub">
        <sc:textLeaf role="ind">
          <xsl:apply-templates select="./* | ./text()"/>
        </sc:textLeaf>
      </xsl:template>
      <xsl:template match="h:sup">
        <sc:textLeaf role="exp">
          <xsl:apply-templates select="./* | ./text()"/>
        </sc:textLeaf>
      </xsl:template>
      <xsl:template match="h:a">
        <sc:phrase role="url">
          <op:urlM>
            <sp:url>
              <xsl:value-of select="./@href"/>
            </sp:url>
          </op:urlM>
          <xsl:if test="./@title">
            <sp:title>
              <xsl:value-of select="./@title"/>
            </sp:title>
          </xsl:if>
          <xsl:value-of select="." />
        </sc:phrase>
      </xsl:template>

      <!-- References -->
      <xsl:template match="h:a[@data-hdoc-type = 'bibtexml']">
        <sc:uLink role="bib" sc:refUri="references/{substring-before(@href,'.')}/{substring-after(@href,'#')}.ref">
          <xsl:apply-templates select="./* | ./text()"/>
        </sc:uLink>
      </xsl:template>

      <xsl:template match="h:li">
        <sc:listItem>
          <xsl:apply-templates select="./* | ./text()"/>
        </sc:listItem>
      </xsl:template>
      <xsl:template match="h:span[@data-hdoc-type = 'syntax']">
        <sc:inlineStyle role="code">
          <xsl:apply-templates select="./* | ./text()"/>
        </sc:inlineStyle>
      </xsl:template>
      <xsl:template match="h:span[@data-hdoc-type = 'latex']">
        <sc:textLeaf role="mathtex">
          <xsl:apply-templates select="./* | ./text()"/>
        </sc:textLeaf>        
      </xsl:template>
      <xsl:template match="h:span">
       <xsl:apply-templates select="./* | ./text()"/>
      </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>
              <op: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>
              </op: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>
  
    <!-- Ressource related templates -->
      <xsl:template match="h:img">
        <sp:res sc:refUri="res/{./@src}">
          <op:resInfoM/>
        </sp:res>
      </xsl:template>
      <xsl:template match="h:audio">
        <sp:res sc:refUri="res/{./@src}">
          <op:resInfoM/>
        </sp:res>
      </xsl:template>
      <xsl:template match="h:video">
        <sp:res sc:refUri="res/{./@src}">
          <op:resInfoM/>
        </sp:res>
      </xsl:template>
      <xsl:template match="h:object">
    <sp:int sc:refUri="res/{./@data}">
      <op:instructionM/>
    </sp:int>
  </xsl:template>
619 620
  
  <!-- Listing Informatique-->
621
  <xsl:template match="h:object[@type='application/x-listing']" priority="1">
622
    <sp:listing>
623
      <xsl:copy-of select="document(fn:concat($filename,'/decompressedHdoc/',@data))/sc:item/op:code"/>
624 625
    </sp:listing>
  </xsl:template>
626
  
Neveux Anais's avatar
Neveux Anais committed
627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677
  <!-- Match exercise -->
  <xsl:template match="h:section[@data-hdoc-type = 'match']" priority="2">
    <sp:trainUcMatch>
      <op:match>
        <op:exeM>
          <sp:title><xsl:value-of select="h:header/h:h1"/></sp:title>
        </op:exeM>
        <xsl:apply-templates select="h:div[@data-hdoc-type = 'question']"/>
        <xsl:apply-templates select="h:section[@data-hdoc-type = 'group']"/>
        
        <sc:globalExplanation>
          <op:res>
            <xsl:apply-templates select="./h:div[@data-hdoc-type = 'explanation']/h:p"/>
          </op:res>
        </sc:globalExplanation>     
      </op:match>
    </sp:trainUcMatch>
  </xsl:template>
  
  <xsl:template match="h:section[@data-hdoc-type = 'group']" priority="2">
    <sc:group>
      <xsl:apply-templates select="h:div[@data-hdoc-type = 'target']"/>
      <xsl:apply-templates select="h:div[@data-hdoc-type = 'label']"/>
    </sc:group>
  </xsl:template>
  
  
  <xsl:template match="h:section[@data-hdoc-type = 'group']/h:div[@data-hdoc-type = 'label']" priority="2">
    <sc:label>
      <op:label>
        <sp:txt>
          <op:labelTxt>
            <xsl:apply-templates select="./*"/>
          </op:labelTxt>
        </sp:txt>
      </op:label>
    </sc:label>
  </xsl:template>
  
  <xsl:template match="h:div[@data-hdoc-type = 'target']">
    <sc:target>
      <op:label>
        <sp:txt>
          <op:labelTxt>
            <xsl:apply-templates select="./*"/>
          </op:labelTxt>
        </sp:txt>
      </op:label>
    </sc:target>
  </xsl:template>
  
Neveux Anais's avatar
Neveux Anais committed
678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704
  <!-- Order exercise -->
  <xsl:template match="h:section[@data-hdoc-type = 'order']" priority="2">
    <sp:trainUcOrdWord>
      <op:ordWord>
        <op:exeM>
          <sp:title><xsl:value-of select="h:header/h:h1"/></sp:title>
        </op:exeM>
        <xsl:apply-templates select="h:div[@data-hdoc-type='question']"/>
        <xsl:apply-templates select="h:div[@data-hdoc-type= 'label']"/>
      
        <sc:globalExplanation>
          <op:res>
            <xsl:apply-templates select="./h:div[@data-hdoc-type = 'explanation']/h:p"/>
          </op:res>
        </sc:globalExplanation>
      </op:ordWord>
    </sp:trainUcOrdWord>
  </xsl:template>
  
  <xsl:template match="h:div[@data-hdoc-type = 'label']">
    <sc:label>
      <op:labelTxt>
        <xsl:apply-templates select="./*"/>
      </op:labelTxt>
    </sc:label>
  </xsl:template>
  
Neveux Anais's avatar
Neveux Anais committed
705
  
706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738
  <!-- Fill-in-the-blank -->
  <xsl:template match="h:section[@data-hdoc-type = 'fill-in-the-blank']" priority="2">
    <sp:trainUcCloze>
      <op:cloze>
        <op:exeM>
          <sp:title><xsl:value-of select="h:header/h:h1"/></sp:title>
        </op:exeM>
        <xsl:apply-templates select="h:div[@data-hdoc-type = 'question']"/>
        <xsl:apply-templates select="h:div[@data-hdoc-type = 'gapText']"/>
        
        <sc:globalExplanation>
          <op:res>
            <xsl:apply-templates select="./h:div[@data-hdoc-type = 'explanation']/h:p"/>
          </op:res>
        </sc:globalExplanation>
      </op:cloze>
    </sp:trainUcCloze>
  </xsl:template>
  
  <xsl:template match="h:div[@data-hdoc-type = 'gapText']">
    <sc:gapText>
      <op:clozeTxt>
        <xsl:apply-templates select="./*"/>
      </op:clozeTxt>
    </sc:gapText>
  </xsl:template>
  
  <xsl:template match="h:span[@data-hdoc-type = 'blank']">
    <sc:textLeaf role="gap">
      <xsl:apply-templates select="./* | ./text()"/>
    </sc:textLeaf>    
  </xsl:template>
  
739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806
  <!-- Open Question -->
  <xsl:template match="h:section[@data-hdoc-type = 'exercise']">
    <sp:practUc>
      <op:practUc>
        <op:exeM>
          <sp:title>
            <xsl:value-of select="h:header/h:h1"/>
          </sp:title>
        </op:exeM>
        <!-- TODO handle desc -->
        
        <!-- Question/Response -->
        <xsl:apply-templates select=".//h:section"/>
        
      </op:practUc>
    </sp:practUc>
  </xsl:template>
  
  <xsl:template match="h:section[h:div[@data-hdoc-type='openQuestion']]">
    <sp:quest>
      <op:practUcQ>
        <sp:desc>
          <xsl:apply-templates select="./h:div[@data-hdoc-type = 'openQuestion']"/>
          
        </sp:desc>
        <sp:hint>
          <xsl:apply-templates select="./h:div[@data-hdoc-type = 'hint']"/>
          
        </sp:hint>

        <xsl:if test="h:div[@data-hdoc-type = 'solution']">
          <sp:sol>
            <op:pb>
              <xsl:apply-templates select="./h:div[@data-hdoc-type = 'solution']"/>
            </op:pb>
          </sp:sol>
        </xsl:if>
      </op:practUcQ>
    </sp:quest>
  </xsl:template>
 
 <xsl:template match="h:div[@data-hdoc-type = 'openQuestion']">
   <op:res>
     <xsl:apply-templates select="./*"/>
   </op:res>
 </xsl:template>
  
  <xsl:template match="h:div[@data-hdoc-type = 'hint']">
    <op:res>
      <xsl:apply-templates select="./*"/>
    </op:res>
  </xsl:template>

  <xsl:template match="h:section[parent::h:section[@data-hdoc-type='exercise']]/h:div[@data-hdoc-type = 'solution']" priority="1">
    <!-- TODO add warning/ect... blocks -->
    <sp:info>
      <op:pbTi>
        <xsl:if test="string-length(./h:h6/text()) > 0">
          <sp:title>
            <xsl:value-of select="./h:h6"/>
          </sp:title>
        </xsl:if>
      </op:pbTi>
      <op:res>
        <xsl:apply-templates select="./*"/>
      </op:res>
    </sp:info>
  </xsl:template>
807

808
  <!-- MCQ-->
809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828
  <xsl:template match="h:section[h:div[@data-hdoc-type = 'question']]">
    <sp:trainUcMcqMur>
      <op:mcqMur>
        <op:exeM>
          <sp:title>
            <xsl:value-of select="./h:header/h:h1"/>
          </sp:title>
        </op:exeM>
        <xsl:apply-templates select="./h:div[@data-hdoc-type = 'question']" />
        <sc:choices>
          <xsl:apply-templates select="./h:div[@data-hdoc-type = 'choice-correct' or @data-hdoc-type = 'choice-incorrect']"/>
        </sc:choices>
        <sc:globalExplanation>
          <op:res>
            <xsl:apply-templates select="./h:div[@data-hdoc-type = 'explanation']/h:p"/>
          </op:res>
        </sc:globalExplanation>
      </op:mcqMur>
    </sp:trainUcMcqMur>
  </xsl:template>
829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852
  
  <!-- Single choice question-->
  <xsl:template match="h:section[h:div[@data-hdoc-type = 'singlechoicequestion']]">
    <!-- Selecting the first question -->
    <sp:trainUcMcqSur>
      <op:mcqSur>
        <op:exeM>
          <sp:title>
            <xsl:value-of select="./h:header/h:h1"/>
          </sp:title>
        </op:exeM>
        <xsl:apply-templates select="./h:div[@data-hdoc-type = 'singlechoicequestion']" />
        <sc:choices>
          <xsl:apply-templates select="./h:div[@data-hdoc-type = 'choice']"></xsl:apply-templates>
        </sc:choices>
        <xsl:apply-templates select="./h:div[@data-hdoc-type = 'solution']" />
        <sc:globalExplanation>
          <op:res>
            <xsl:apply-templates select="./h:div[@data-hdoc-type = 'explanation']/h:p"/>
          </op:res>
        </sc:globalExplanation>
      </op:mcqSur>
    </sp:trainUcMcqSur>
  </xsl:template>
853

854 855
  <!-- Question within MCQ and single choice question-->
  <xsl:template match="h:div[@data-hdoc-type = 'question' or @data-hdoc-type = 'singlechoicequestion']"> 
856 857 858 859 860 861 862
    <sc:question>
      <op:res>
        <xsl:apply-templates select="./*" />
      </op:res>
    </sc:question>
  </xsl:template>

863
  <!-- Question within MCQ and single choice question-->
864 865 866
  <xsl:template match="h:div[@data-hdoc-type = 'choice-correct']"> 
    <sc:choice solution="checked">
      <xsl:call-template name="choice" />
867
      <sc:choiceExplanation>
868 869 870 871 872 873
      <op:txt>
        <sc:para>
          <xsl:apply-templates select="./h:div[@data-hdoc-type = 'explanation-choice-correct']/h:p/text()"/>
        </sc:para>
      </op:txt>
    </sc:choiceExplanation>
874 875
    </sc:choice>
  </xsl:template>
876
  
877 878 879
  <xsl:template match="h:div[@data-hdoc-type = 'choice-incorrect']"> 
    <sc:choice solution="unchecked">
      <xsl:call-template name="choice" />
880 881 882 883 884 885 886
      <sc:choiceExplanation>
        <op:txt>
          <sc:para>
            <xsl:apply-templates select="./h:div[@data-hdoc-type = 'explanation-choice-incorrect']/h:p/text()"/>
          </sc:para>
        </op:txt>
      </sc:choiceExplanation>
887 888
    </sc:choice>
  </xsl:template>
889 890 891 892
  
  <xsl:template match="./h:div[@data-hdoc-type = 'choice']">
    <sc:choice>
      <xsl:call-template name="choice" />
893 894 895 896 897 898 899 900 901
      <xsl:if test="h:div[@data-hdoc-type = 'explanation-choice-correct']">
        <sc:choiceExplanation>
          <op:txt>
            <sc:para>
              <xsl:apply-templates select="./h:div[@data-hdoc-type = 'explanation-choice-correct']/h:p/text()"/>
            </sc:para>
          </op:txt>
        </sc:choiceExplanation>
      </xsl:if>
902 903
    </sc:choice>
  </xsl:template>
904

905
  
906 907 908 909 910 911 912 913 914 915 916
  <xsl:template name="choice">
    <sc:choiceLabel>
      <op:txt>
        <!-- TODO formating won't work -->
        <sc:para>
          <xsl:apply-templates select="./h:p/text()" />
        </sc:para>
      </op:txt>
    </sc:choiceLabel>
  </xsl:template>
  
917 918 919 920 921 922
  <xsl:template match="h:div[@data-hdoc-type = 'solution']">
    <sc:solution>
      <xsl:attribute name="choice">
        <xsl:value-of select="./h:p"></xsl:value-of>
      </xsl:attribute>
    </sc:solution>
923
  </xsl:template>  
924
  
925 926 927 928 929 930 931 932 933 934 935
  <!-- These markups are matched in order to minimize "apply-templates select="./*" side-effects (i.e. their content are already treated into another template or they are not (yet) supported). -->
    <!-- Unsupported. -->
      <xsl:template match="h:div[@data-hdoc-types = 'categories']"/> 
      <xsl:template match="h:meta[@charset]"/>
      <xsl:template match="h:meta[@generator]"/>
      <xsl:template match="h:footer/h:div[@data-hdoc-type = 'categories']"/>
    <!-- Other. -->
      <!--<xsl:template match="h:span"/>--> <!-- Its content is already used in several templates, according to its location and microdata. -->
      <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"> -->
Ivan D'halluin's avatar
Ivan D'halluin committed
936
</xsl:stylesheet>