sect.xsl 4.92 KB
Newer Older
1
<?xml version="1.0" encoding="UTF-8"?>
Bastien FREMONDIERE's avatar
Fix bug  
Bastien FREMONDIERE committed
2
3
4
5
6
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns="http://www.utc.fr/ics/hdoc/xhtml" xmlns:utc="http://www.utc.fr/ics/hdoc/xhtml"
    xmlns:xs="http://www.w3.org/2001/XMLSchema">
    <!-- This is wrong -> xpath-default-namespace="http://www.utc.fr/ics/hdoc/xhtml"-->

7
    <xsl:output method="xml" indent="yes"/>
8
    <!-- Remove spaces/tabs -->
Bastien FREMONDIERE's avatar
Fix bug  
Bastien FREMONDIERE committed
9
10
    <xsl:strip-space elements="*"/>

11
    <!-- Entry point -->
12
13
14
15
16
17
    <xsl:template match="map">
        <xsl:processing-instruction name="oxygen">
            RNGSchema="http://scenari.utc.fr/hdoc/schemas/xhtml/hdoc1-xhtml.rng" type="xml"
        </xsl:processing-instruction>
        <html>
            <head>
Bastien FREMONDIERE's avatar
Fix bug  
Bastien FREMONDIERE committed
18
                <xsl:apply-templates mode="header"/>
19
            </head>
Bastien FREMONDIERE's avatar
Fix bug  
Bastien FREMONDIERE committed
20
            <body>
21
22
23
                <xsl:apply-templates/>
            </body>
        </html>
Bastien FREMONDIERE's avatar
Fix bug  
Bastien FREMONDIERE committed
24

25
    </xsl:template>
Bastien FREMONDIERE's avatar
Fix bug  
Bastien FREMONDIERE committed
26

27
    <!-- Header in hdoc -->
28
    <xsl:template match="node[1]" mode="header">
Bastien FREMONDIERE's avatar
Fix bug  
Bastien FREMONDIERE committed
29
        <title>
Zangdar1111's avatar
Zangdar1111 committed
30
            <xsl:value-of select="utc:remove-language(@TEXT)"/>
Bastien FREMONDIERE's avatar
Bastien FREMONDIERE committed
31
            <xsl:value-of select="richcontent"/>
Bastien FREMONDIERE's avatar
Fix bug  
Bastien FREMONDIERE committed
32
33
34
        </title>
        <meta charset="utf-8"/>
        <meta name="author" content=""/>
35
    </xsl:template>
Bastien FREMONDIERE's avatar
Fix bug  
Bastien FREMONDIERE committed
36

Bastien FREMONDIERE's avatar
Bastien FREMONDIERE committed
37
    <!-- Default behavior for node -->
38
    <xsl:template match="node">
Bastien FREMONDIERE's avatar
Fix bug  
Bastien FREMONDIERE committed
39
        <xsl:element name="section">
40
41
            <header>
                <h1>
Zangdar1111's avatar
Zangdar1111 committed
42
                    <xsl:value-of select="utc:remove-language(@TEXT)"/>
Bastien FREMONDIERE's avatar
Fix bug  
Bastien FREMONDIERE committed
43
                    <xsl:value-of select="richcontent"/>
44
45
                </h1>
            </header>
46
47
48
            <!--Introduction-->
            <xsl:if test="child::*[contains(@TEXT, '#intro')]">
                <xsl:element name="section">
49
50
51
                    <header><h1>Introduction</h1>
                        <xsl:element name="div">
                            <xsl:attribute name="data-hdoc-type">introduction</xsl:attribute>
Zangdar1111's avatar
Zangdar1111 committed
52
                            <xsl:value-of select="utc:remove-language(child::*[contains(@TEXT, '#intro')][1]/@TEXT)"/>
53
54
                        </xsl:element>
                   </header>
55
56
57
                </xsl:element>
            </xsl:if>
            <!-- Process children -->
Bastien FREMONDIERE's avatar
Bastien FREMONDIERE committed
58
            <xsl:apply-templates select="node"/>
59
60
61
            <!--Conclusion-->
            <xsl:if test="child::*[contains(@TEXT, '#conclu')]">
                <xsl:element name="section">
Zangdar1111's avatar
Zangdar1111 committed
62
                    <header><h1>Conclusion</h1></header>
63
64
65
                    <footer>
                        <xsl:element name="div">
                            <xsl:attribute name="data-hdoc-type">conclusion</xsl:attribute>
Zangdar1111's avatar
Zangdar1111 committed
66
                            <xsl:value-of select="utc:remove-language(child::*[contains(@TEXT, '#conclu')][1]/@TEXT)"/>
67
68
                        </xsl:element>
                    </footer>
69
70
                </xsl:element>
            </xsl:if>
71
72
        </xsl:element>
    </xsl:template>
Bastien FREMONDIERE's avatar
Fix bug  
Bastien FREMONDIERE committed
73

Bastien FREMONDIERE's avatar
Bastien FREMONDIERE committed
74
    <!-- Behavior when node has no children -->
Bastien FREMONDIERE's avatar
Fix bug  
Bastien FREMONDIERE committed
75
    <xsl:template
Bastien FREMONDIERE's avatar
Bastien FREMONDIERE committed
76
        match="node[not(node)]|node[child::*[contains(@TEXT, '#p')]]|node[child::*[contains(@TEXT, '#a')]]"
Bastien FREMONDIERE's avatar
Fix bug  
Bastien FREMONDIERE committed
77
78
        priority="1">
        <xsl:element name="section">
79
            <xsl:attribute name="data-hdoc-type">unit-of-content</xsl:attribute>
80
81
82
83
84
            <xsl:if test="child::attribute[@NAME='anchor']">
                <xsl:attribute name="id">
                    <xsl:value-of select="child::attribute[@NAME='anchor'][1]/@VALUE"></xsl:value-of>
                </xsl:attribute>
            </xsl:if>
85
86
            <header>
                <h1>
Zangdar1111's avatar
Zangdar1111 committed
87
                    <xsl:value-of select="utc:remove-language(@TEXT)"/>
Bastien FREMONDIERE's avatar
Fix bug  
Bastien FREMONDIERE committed
88
                    <xsl:value-of select="richcontent"/>
89
90
                </h1>
            </header>
Bastien FREMONDIERE's avatar
Bastien FREMONDIERE committed
91
            <xsl:apply-templates/>
Bastien FREMONDIERE's avatar
Bastien FREMONDIERE committed
92
93
        </xsl:element>
    </xsl:template>
Bastien FREMONDIERE's avatar
Fix bug  
Bastien FREMONDIERE committed
94

95
    <!-- Paragraph -->
Bastien FREMONDIERE's avatar
Bastien FREMONDIERE committed
96
97
    <xsl:template match="node[contains(@TEXT, '#p')]" priority="2">
        <xsl:element name="p">
Zangdar1111's avatar
Zangdar1111 committed
98
            <xsl:value-of select="utc:remove-language(@TEXT)"/>
99
100
101
        </xsl:element>
    </xsl:template>

102
    <!-- Link : need to use anchor attribute ? -->
Bastien FREMONDIERE's avatar
Bastien FREMONDIERE committed
103
104
105
106
    <xsl:template match="node[contains(@TEXT, '#a')]" priority="2">
        <xsl:element name="a">
            <xsl:attribute name="href">
                <xsl:text>#</xsl:text>
Zangdar1111's avatar
Zangdar1111 committed
107
                <xsl:value-of select="utc:remove-language(@TEXT)"/>
Bastien FREMONDIERE's avatar
Bastien FREMONDIERE committed
108
            </xsl:attribute>
Zangdar1111's avatar
Zangdar1111 committed
109
            <xsl:value-of select="utc:remove-language(@TEXT)"/>
Bastien FREMONDIERE's avatar
Bastien FREMONDIERE committed
110
111
        </xsl:element>
    </xsl:template>
112

113
114
115
    <!-- Default behavior for intro and conclu nodes : do nothing -->
    <xsl:template match="node[contains(@TEXT, '#intro')] | node[contains(@TEXT, '#conclu')]" priority="3"/>

Bastien FREMONDIERE's avatar
Bastien FREMONDIERE committed
116
    <xsl:template match="richcontent">
Zangdar1111's avatar
Zangdar1111 committed
117
        <xsl:value-of select="utc:remove-language(html/body/p)"/>
Bastien FREMONDIERE's avatar
Bastien FREMONDIERE committed
118
    </xsl:template>
Bastien FREMONDIERE's avatar
Fix bug  
Bastien FREMONDIERE committed
119

Bastien FREMONDIERE's avatar
Bastien FREMONDIERE committed
120
    <!-- Utility functions -->
Zangdar1111's avatar
Zangdar1111 committed
121
    <xsl:function name="utc:remove-language" as="xs:string">
Zangdar1111's avatar
Zangdar1111 committed
122
123
        <xsl:param name="text" as="xs:string?" />
        <xsl:variable name="text2" select="string($text)"/>
Zangdar1111's avatar
Zangdar1111 committed
124
        <xsl:value-of select="replace($text2,'(#[0-9a-z]* )+','')"></xsl:value-of>
Zangdar1111's avatar
Zangdar1111 committed
125
126
    </xsl:function>
	 
127
</xsl:stylesheet>