last_transformer.xsl 3.42 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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
  <!-- Traitement des liens hypertextes pour autoriser le saut à la ligne-->
  <xsl:template match="a">
    <a>
      <xsl:copy-of select="@*" />
      <xsl:call-template name="addWordBreak">
        <xsl:with-param name="input" select="."/>
      </xsl:call-template>
    </a>
  </xsl:template>

  <xsl:template name="addWordBreak">
    <xsl:param name="input"/>
    <xsl:value-of select="substring($input,1,1)"/><wbr />
    <xsl:if test="substring($input,2)">
      <xsl:call-template name="addWordBreak">
        <xsl:with-param name="input" select="substring($input,2)"/>
      </xsl:call-template>
    </xsl:if>
  </xsl:template>

50
51
52

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


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

57
  <xsl:template name="toc">
bperraud's avatar
bperraud committed
58

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

62
       <xsl:choose>
bperraud's avatar
bperraud committed
63

64
65
66
         <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
67

68
69
70
71
             <ul class="toc level2">
               <xsl:for-each select="//*[local-name()=$hnlevel]">
                 <li>
                   <xsl:call-template name="toc-a"/>
bperraud's avatar
bperraud committed
72

73
74
75
                   <xsl:call-template name="toc">
                     <xsl:with-param name="toclevel" select="3"/>
                   </xsl:call-template>
bperraud's avatar
bperraud committed
76

77
78
79
80
81
                 </li>
               </xsl:for-each>
             </ul>
           </xsl:if>
         </xsl:when>
bperraud's avatar
bperraud committed
82

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

86
87
88
89
             <ul class="toc level{$toclevel}">
               <xsl:for-each select="..//*[local-name()=$hnlevel]">
                 <li>
                   <xsl:call-template name="toc-a"/>
bperraud's avatar
bperraud committed
90

91
                   <xsl:if test="$toclevel &lt; 4">
92
93
94
95
96
97
98
99
100
                     <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
101

102
       </xsl:choose>
bperraud's avatar
bperraud committed
103

104
   </xsl:template>
bperraud's avatar
bperraud committed
105

bperraud's avatar
bperraud committed
106
107
108
109
110
111
112
113
  <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
114
115
116
117
118
119
    <span>
      <xsl:attribute name="href">
        <xsl:text>#</xsl:text>
        <xsl:value-of select="./@id"/>
      </xsl:attribute>
    </span>
bperraud's avatar
bperraud committed
120
  </xsl:template>
bperraud's avatar
bperraud committed
121
122
123



124
</xsl:stylesheet>