sect.xsl 4.74 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"/>
Bastien FREMONDIERE's avatar
Fix bug    
Bastien FREMONDIERE committed
8
9
    <xsl:strip-space elements="*"/>

10
11
12
13
14
15
    <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
16
                <xsl:apply-templates mode="header"/>
17
            </head>
Bastien FREMONDIERE's avatar
Fix bug    
Bastien FREMONDIERE committed
18
            <body>
19
20
21
                <xsl:apply-templates/>
            </body>
        </html>
Bastien FREMONDIERE's avatar
Fix bug    
Bastien FREMONDIERE committed
22

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


26
    <xsl:template match="node[1]" mode="header">
Bastien FREMONDIERE's avatar
Fix bug    
Bastien FREMONDIERE committed
27
        <title>
Bastien FREMONDIERE's avatar
Bastien FREMONDIERE committed
28
29
            <xsl:value-of select="@TEXT"/>
            <xsl:value-of select="richcontent"/>
Bastien FREMONDIERE's avatar
Fix bug    
Bastien FREMONDIERE committed
30
31
32
        </title>
        <meta charset="utf-8"/>
        <meta name="author" content=""/>
33
    </xsl:template>
Bastien FREMONDIERE's avatar
Fix bug    
Bastien FREMONDIERE committed
34

Bastien FREMONDIERE's avatar
Bastien FREMONDIERE committed
35
    <!-- Default behavior for node -->
36
    <xsl:template match="node">
Bastien FREMONDIERE's avatar
Fix bug    
Bastien FREMONDIERE committed
37
        <xsl:element name="section">
38
39
            <header>
                <h1>
Zangdar1111's avatar
Zangdar1111 committed
40
41
                    <xsl:value-of select="utc:string-remove-order('#1 test')"></xsl:value-of>
                    <xsl:value-of select="utc:string-remove-order(@TEXT)"/>
Bastien FREMONDIERE's avatar
Fix bug    
Bastien FREMONDIERE committed
42
                    <xsl:value-of select="richcontent"/>
43
44
                </h1>
            </header>
Zangdar1111's avatar
Zangdar1111 committed
45
46
47
            <xsl:apply-templates select="./node">
                <xsl:sort select="string(999-number(substring-after(tokenize(@TEXT,' ')[matches(.,'#([1-9][0-9]*)')],'#')))" order="descending" data-type="number" stable="yes"></xsl:sort>
            </xsl:apply-templates>
48
49
        </xsl:element>
    </xsl:template>
Bastien FREMONDIERE's avatar
Fix bug    
Bastien FREMONDIERE committed
50

Bastien FREMONDIERE's avatar
Bastien FREMONDIERE committed
51
    <!-- Behavior when node has no children -->
Bastien FREMONDIERE's avatar
Fix bug    
Bastien FREMONDIERE committed
52
    <xsl:template
Bastien FREMONDIERE's avatar
Bastien FREMONDIERE committed
53
        match="node[not(node)]|node[child::*[contains(@TEXT, '#p')]]|node[child::*[contains(@TEXT, '#a')]]"
Bastien FREMONDIERE's avatar
Fix bug    
Bastien FREMONDIERE committed
54
55
        priority="1">
        <xsl:element name="section">
56
57
58
            <xsl:attribute name="data-hdoc-type">unit-of-content</xsl:attribute>
            <header>
                <h1>
Zangdar1111's avatar
Zangdar1111 committed
59
                    <xsl:value-of select="utc:string-remove-order(@TEXT)"/>
Bastien FREMONDIERE's avatar
Fix bug    
Bastien FREMONDIERE committed
60
                    <xsl:value-of select="richcontent"/>
61
62
                </h1>
            </header>
Bastien FREMONDIERE's avatar
Bastien FREMONDIERE committed
63
            <xsl:apply-templates/>
Bastien FREMONDIERE's avatar
Bastien FREMONDIERE committed
64
65
        </xsl:element>
    </xsl:template>
Bastien FREMONDIERE's avatar
Fix bug    
Bastien FREMONDIERE committed
66

Bastien FREMONDIERE's avatar
Bastien FREMONDIERE committed
67
68
    <xsl:template match="node[contains(@TEXT, '#p')]" priority="2">
        <xsl:element name="p">
Zangdar1111's avatar
Zangdar1111 committed
69
            <xsl:value-of select="utc:string-remove-order(utc:string-remove-all(@TEXT, '#p '))"/>
70
71
72
        </xsl:element>
    </xsl:template>

Bastien FREMONDIERE's avatar
Bastien FREMONDIERE committed
73
74
75
76
    <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
77
                <xsl:value-of select="utc:string-remove-order(utc:string-remove-all(@TEXT, '#a '))"/>
Bastien FREMONDIERE's avatar
Bastien FREMONDIERE committed
78
            </xsl:attribute>
Zangdar1111's avatar
Zangdar1111 committed
79
            <xsl:value-of select="utc:string-remove-order(utc:string-remove-all(@TEXT, '#a '))"/>
Bastien FREMONDIERE's avatar
Bastien FREMONDIERE committed
80
81
        </xsl:element>
    </xsl:template>
82

Bastien FREMONDIERE's avatar
Bastien FREMONDIERE committed
83
    <xsl:template match="richcontent">
Bastien FREMONDIERE's avatar
Fix bug    
Bastien FREMONDIERE committed
84
        <xsl:value-of select="html/body/p"/>
Bastien FREMONDIERE's avatar
Bastien FREMONDIERE committed
85
    </xsl:template>
Bastien FREMONDIERE's avatar
Fix bug    
Bastien FREMONDIERE committed
86

Bastien FREMONDIERE's avatar
Bastien FREMONDIERE committed
87
    <!-- Utility functions -->
Bastien FREMONDIERE's avatar
Fix bug    
Bastien FREMONDIERE committed
88

Bastien FREMONDIERE's avatar
Bastien FREMONDIERE committed
89
90
    <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
91
        <xsl:param name="replace" as="xs:string"/>
Bastien FREMONDIERE's avatar
Bastien FREMONDIERE committed
92
93
94
95
96
97
98
        <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>
        <xsl:value-of select="$ret"></xsl:value-of>
Bastien FREMONDIERE's avatar
Fix bug    
Bastien FREMONDIERE committed
99
100
    </xsl:function>

Bastien FREMONDIERE's avatar
Bastien FREMONDIERE committed
101
102
    <xsl:template name="string-remove-all">
        <xsl:param name="text" as="xs:string"/>
Bastien FREMONDIERE's avatar
Fix bug    
Bastien FREMONDIERE committed
103
        <xsl:param name="replace" as="xs:string"/>
Bastien FREMONDIERE's avatar
Bastien FREMONDIERE committed
104
105
        <xsl:choose>
            <xsl:when test="contains($text, $replace)">
Bastien FREMONDIERE's avatar
Fix bug    
Bastien FREMONDIERE committed
106
                <xsl:value-of select="substring-before($text,$replace)"/>
Bastien FREMONDIERE's avatar
Bastien FREMONDIERE committed
107
                <xsl:call-template name="string-remove-all">
Bastien FREMONDIERE's avatar
Fix bug    
Bastien FREMONDIERE committed
108
109
                    <xsl:with-param name="text" select="substring-after($text,$replace)"/>
                    <xsl:with-param name="replace" select="$replace"/>
Bastien FREMONDIERE's avatar
Bastien FREMONDIERE committed
110
111
112
                </xsl:call-template>
            </xsl:when>
            <xsl:otherwise>
Bastien FREMONDIERE's avatar
Fix bug    
Bastien FREMONDIERE committed
113
                <xsl:value-of select="$text"/>
Bastien FREMONDIERE's avatar
Bastien FREMONDIERE committed
114
115
116
            </xsl:otherwise>
        </xsl:choose>
    </xsl:template>
Zangdar1111's avatar
Zangdar1111 committed
117
118
119
120
121
122
123
    
    <xsl:function name="utc:string-remove-order" as="xs:string">
        <xsl:param name="text" as="xs:string?" />
        <xsl:variable name="text2" select="string($text)"/>
        <xsl:value-of select="replace($text2,'#[1-9][0-9]* ','')"></xsl:value-of>
    </xsl:function>
    
124
</xsl:stylesheet>