last_transformer.xsl 2.8 KB
Newer Older
1
<?xml version="1.0" encoding="UTF-8"?>
2
3

<xsl:stylesheet
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0"
  xpath-default-namespace="http://www.w3.org/1999/xhtml"
  xmlns="http://www.w3.org/1999/xhtml">

  <xsl:output method="xml" indent="yes"/>

  <xsl:template match="node()|@*">
    <xsl:copy>
      <xsl:apply-templates select="node()|@*"/>
    </xsl:copy>
  </xsl:template>

  <!-- Traitement du titre et des auteurs du document -->
  <xsl:template match="body">
    <body>
      <h1><xsl:value-of select="/html/head/title"/></h1>
      <p class="authors"><xsl:value-of select="/html/head/meta[@name='author']/@content"/></p>
bperraud's avatar
bperraud committed
21

22
      <xsl:apply-templates select="node()|@*"/>
bperraud's avatar
bperraud committed
23

24
25
26
      <xsl:call-template name="toc">
        <xsl:with-param name="toclevel" select="2"/>
      </xsl:call-template>
27
28
    </body>
  </xsl:template>
bperraud's avatar
bperraud committed
29

30
31
32

  <!-- Cleaning des footers vides -->
  <xsl:template match="footer[not(node())]"/>
bperraud's avatar
bperraud committed
33
34


bperraud's avatar
bperraud committed
35
36
  <!-- Gestion de la table des matières -->

37
  <xsl:template name="toc">
bperraud's avatar
bperraud committed
38

39
40
       <xsl:param name="toclevel"/>
       <xsl:variable name="hnlevel" select="concat('h', $toclevel)"/>
bperraud's avatar
bperraud committed
41

42
       <xsl:choose>
bperraud's avatar
bperraud committed
43

44
45
46
         <xsl:when test="$toclevel = 2">
           <xsl:if test="count(//*[local-name()=$hnlevel]) &gt; 0">
             <h2 class="nocount toc-title">Table des matières</h2>
bperraud's avatar
bperraud committed
47

48
49
50
51
             <ul class="toc level2">
               <xsl:for-each select="//*[local-name()=$hnlevel]">
                 <li>
                   <xsl:call-template name="toc-a"/>
bperraud's avatar
bperraud committed
52

53
54
55
                   <xsl:call-template name="toc">
                     <xsl:with-param name="toclevel" select="3"/>
                   </xsl:call-template>
bperraud's avatar
bperraud committed
56

57
58
59
60
61
                 </li>
               </xsl:for-each>
             </ul>
           </xsl:if>
         </xsl:when>
bperraud's avatar
bperraud committed
62

63
64
         <xsl:otherwise>
           <xsl:if test="count(..//*[local-name()=$hnlevel]) &gt; 0">
bperraud's avatar
bperraud committed
65

66
67
68
69
             <ul class="toc level{$toclevel}">
               <xsl:for-each select="..//*[local-name()=$hnlevel]">
                 <li>
                   <xsl:call-template name="toc-a"/>
bperraud's avatar
bperraud committed
70

71
                   <xsl:if test="$toclevel &lt; 4">
72
73
74
75
76
77
78
79
80
                     <xsl:call-template name="toc">
                       <xsl:with-param name="toclevel" select="$toclevel + 1"/>
                     </xsl:call-template>
                   </xsl:if>
                 </li>
               </xsl:for-each>
             </ul>
           </xsl:if>
         </xsl:otherwise>
bperraud's avatar
bperraud committed
81

82
       </xsl:choose>
bperraud's avatar
bperraud committed
83

84
   </xsl:template>
bperraud's avatar
bperraud committed
85

bperraud's avatar
bperraud committed
86
87
88
89
90
91
92
93
  <xsl:template name="toc-a">
    <a>
      <xsl:attribute name="href">
        <xsl:text>#</xsl:text>
        <xsl:value-of select="./@id"/>
      </xsl:attribute>
      <xsl:value-of select="."/>
    </a>
bperraud's avatar
bperraud committed
94
95
96
97
98
99
    <span>
      <xsl:attribute name="href">
        <xsl:text>#</xsl:text>
        <xsl:value-of select="./@id"/>
      </xsl:attribute>
    </span>
bperraud's avatar
bperraud committed
100
  </xsl:template>
bperraud's avatar
bperraud committed
101
102
103



104
</xsl:stylesheet>