last_transformer.xsl 3.82 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
      
      <xsl:call-template name="toc"/>
25
26
    </body>
  </xsl:template>
bperraud's avatar
bperraud committed
27
  
28
29
30

  <!-- Cleaning des footers vides -->
  <xsl:template match="footer[not(node())]"/>
bperraud's avatar
bperraud committed
31
32
33
34
35
36
37
38
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
  
  
  <!-- Gestion de la table des matières -->
  <xsl:template name="toc">
  
    <xsl:if test="count(//h2) &gt; 0">
  
    <h2 class="nocount toc-title">Table des matières</h2>
  
    <ul class="toc level2">
      <xsl:for-each select="//h2">
      
        <li>
          <xsl:call-template name="toc-a"/>
          
          <xsl:if test="count(..//h3) &gt; 0">

            <ul class="toc level3">
              <xsl:for-each select="..//h3">
              
                <li>
                  <xsl:call-template name="toc-a"/>
                  
                  <xsl:if test="count(..//h4) &gt; 0">

                    <ul class="toc level4">
                      <xsl:for-each select="..//h4">
                      
                        <li>
                          <xsl:call-template name="toc-a"/>
                          
                          <xsl:if test="count(..//h5) &gt; 0">

                            <ul class="toc level5">
                              <xsl:for-each select="..//h5">
                              
                                <li>
                                  <xsl:call-template name="toc-a"/>
                                  
                                  <xsl:if test="count(..//h6) &gt; 0">
Baptiste Perraud's avatar
Baptiste Perraud committed
71

bperraud's avatar
bperraud committed
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
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
                                    <ul class="toc level6">
                                      <xsl:for-each select="..//h6">
                                      
                                        <li>
                                          <xsl:call-template name="toc-a"/>
                                          
                                        </li>
                                      </xsl:for-each>
                                    </ul>
                                  
                                  </xsl:if>
                                  
                                </li>
                              </xsl:for-each>
                            </ul>
                          
                          </xsl:if>
                          
                        </li>
                      </xsl:for-each>
                    </ul>
                  
                  </xsl:if>
                  
                </li>
              </xsl:for-each>
            </ul>

          </xsl:if>
          
        </li>
      </xsl:for-each>
    </ul>
    
    </xsl:if>
    <!-- <li><a href="#">Introduction</a><span>1</span></li> -->
    <!-- <li class="nested"> -->
    <!-- <ul class="inner"> -->
    <!-- <li><a href="#">Header 1</a><span>2</span> -->
    <!-- </li> -->
    <!-- <li><a href="#">Header 2</a><span>2</span> -->
    <!-- </li> -->
    <!-- </ul> -->
    <!-- </li> -->
    <!-- <li><a href="#">Header 2</a><span>3</span></li> -->
  
  </xsl:template>
  
  <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>
  </xsl:template>
  
  
  
132
</xsl:stylesheet>