sect.xsl 5.65 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>
Bastien FREMONDIERE's avatar
Bastien FREMONDIERE committed
30
31
            <xsl:value-of select="@TEXT"/>
            <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>
Bastien FREMONDIERE's avatar
Fix bug    
Bastien FREMONDIERE committed
42
43
                    <xsl:value-of select="@TEXT"/>
                    <xsl:value-of select="richcontent"/>
44
45
                </h1>
            </header>
46
47
48
49
50
51
52
53
54
55
            <!--Introduction-->
            <xsl:if test="child::*[contains(@TEXT, '#intro')]">
                <xsl:element name="section">
                    <xsl:attribute name="data-hdoc-type">introduction</xsl:attribute>
                    <xsl:value-of
                        select="utc:string-remove-all(child::*[contains(@TEXT, '#intro')][1]/@TEXT, '#intro ')"
                    />
                </xsl:element>
            </xsl:if>
            <!-- Process children -->
Bastien FREMONDIERE's avatar
Bastien FREMONDIERE committed
56
            <xsl:apply-templates select="node"/>
57
58
59
60
61
62
63
64
65
            <!--Conclusion-->
            <xsl:if test="child::*[contains(@TEXT, '#conclu')]">
                <xsl:element name="section">
                    <xsl:attribute name="data-hdoc-type">conclusion</xsl:attribute>
                    <xsl:value-of
                        select="utc:string-remove-all(child::*[contains(@TEXT, '#conclu')][1]/@TEXT, '#conclu ')"
                    />
                </xsl:element>
            </xsl:if>
66
67
        </xsl:element>
    </xsl:template>
Bastien FREMONDIERE's avatar
Fix bug    
Bastien FREMONDIERE committed
68

Bastien FREMONDIERE's avatar
Bastien FREMONDIERE committed
69
    <!-- Behavior when node has no children -->
Bastien FREMONDIERE's avatar
Fix bug    
Bastien FREMONDIERE committed
70
    <xsl:template
Bastien FREMONDIERE's avatar
Bastien FREMONDIERE committed
71
        match="node[not(node)]|node[child::*[contains(@TEXT, '#p')]]|node[child::*[contains(@TEXT, '#a')]]"
Bastien FREMONDIERE's avatar
Fix bug    
Bastien FREMONDIERE committed
72
73
74
        priority="1">
        <xd:doc xmlns:xd="http://www.oxygenxml.com/ns/doc/xsl">
            <xd:desc>
75
                <xd:p/> 
Bastien FREMONDIERE's avatar
Fix bug    
Bastien FREMONDIERE committed
76
77
78
            </xd:desc>
        </xd:doc>
        <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>
Bastien FREMONDIERE's avatar
Fix bug    
Bastien FREMONDIERE committed
87
88
                    <xsl:value-of select="@TEXT"/>
                    <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">
Bastien FREMONDIERE's avatar
Fix bug    
Bastien FREMONDIERE committed
98
            <xsl:value-of select="utc:string-remove-all(@TEXT, '#p ')"/>
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>
Bastien FREMONDIERE's avatar
Fix bug    
Bastien FREMONDIERE committed
107
                <xsl:value-of select="utc:string-remove-all(@TEXT, '#a ')"/>
Bastien FREMONDIERE's avatar
Bastien FREMONDIERE committed
108
            </xsl:attribute>
Bastien FREMONDIERE's avatar
Fix bug    
Bastien FREMONDIERE committed
109
            <xsl:value-of select="utc:string-remove-all(@TEXT, '#a ')"/>
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">
Bastien FREMONDIERE's avatar
Fix bug    
Bastien FREMONDIERE committed
117
        <xsl:value-of select="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
121
122
    <!-- Utility functions -->
    <xsl:function name="utc:string-remove-all" as="xs:string">
        <xsl:param name="text" as="xs:string"/>
Bastien FREMONDIERE's avatar
Fix bug    
Bastien FREMONDIERE committed
123
        <xsl:param name="replace" as="xs:string"/>
Bastien FREMONDIERE's avatar
Bastien FREMONDIERE committed
124
125
126
127
128
129
        <xsl:variable name="ret">
            <xsl:call-template name="string-remove-all">
                <xsl:with-param name="text" select="$text"/>
                <xsl:with-param name="replace" select="$replace"/>
            </xsl:call-template>
        </xsl:variable>
130
        <xsl:value-of select="$ret"/>
Bastien FREMONDIERE's avatar
Fix bug    
Bastien FREMONDIERE committed
131
132
    </xsl:function>

Bastien FREMONDIERE's avatar
Bastien FREMONDIERE committed
133
134
    <xsl:template name="string-remove-all">
        <xsl:param name="text" as="xs:string"/>
Bastien FREMONDIERE's avatar
Fix bug    
Bastien FREMONDIERE committed
135
        <xsl:param name="replace" as="xs:string"/>
Bastien FREMONDIERE's avatar
Bastien FREMONDIERE committed
136
137
        <xsl:choose>
            <xsl:when test="contains($text, $replace)">
Bastien FREMONDIERE's avatar
Fix bug    
Bastien FREMONDIERE committed
138
                <xsl:value-of select="substring-before($text,$replace)"/>
Bastien FREMONDIERE's avatar
Bastien FREMONDIERE committed
139
                <xsl:call-template name="string-remove-all">
Bastien FREMONDIERE's avatar
Fix bug    
Bastien FREMONDIERE committed
140
141
                    <xsl:with-param name="text" select="substring-after($text,$replace)"/>
                    <xsl:with-param name="replace" select="$replace"/>
Bastien FREMONDIERE's avatar
Bastien FREMONDIERE committed
142
143
144
                </xsl:call-template>
            </xsl:when>
            <xsl:otherwise>
Bastien FREMONDIERE's avatar
Fix bug    
Bastien FREMONDIERE committed
145
                <xsl:value-of select="$text"/>
Bastien FREMONDIERE's avatar
Bastien FREMONDIERE committed
146
147
148
            </xsl:otherwise>
        </xsl:choose>
    </xsl:template>
149
</xsl:stylesheet>