sect.xsl 4.17 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>
Bastien FREMONDIERE's avatar
Fix bug  
Bastien FREMONDIERE committed
40 41
                    <xsl:value-of select="@TEXT"/>
                    <xsl:value-of select="richcontent"/>
42 43
                </h1>
            </header>
Bastien FREMONDIERE's avatar
Bastien FREMONDIERE committed
44
            <xsl:apply-templates select="node"/>
45 46
        </xsl:element>
    </xsl:template>
Bastien FREMONDIERE's avatar
Fix bug  
Bastien FREMONDIERE committed
47

Bastien FREMONDIERE's avatar
Bastien FREMONDIERE committed
48
    <!-- Behavior when node has no children -->
Bastien FREMONDIERE's avatar
Fix bug  
Bastien FREMONDIERE committed
49
    <xsl:template
Bastien FREMONDIERE's avatar
Bastien FREMONDIERE committed
50
        match="node[not(node)]|node[child::*[contains(@TEXT, '#p')]]|node[child::*[contains(@TEXT, '#a')]]"
Bastien FREMONDIERE's avatar
Fix bug  
Bastien FREMONDIERE committed
51 52 53
        priority="1">
        <xd:doc xmlns:xd="http://www.oxygenxml.com/ns/doc/xsl">
            <xd:desc>
Bastien FREMONDIERE's avatar
Bastien FREMONDIERE committed
54
                <xd:p/>
Bastien FREMONDIERE's avatar
Fix bug  
Bastien FREMONDIERE committed
55 56 57
            </xd:desc>
        </xd:doc>
        <xsl:element name="section">
58 59 60
            <xsl:attribute name="data-hdoc-type">unit-of-content</xsl:attribute>
            <header>
                <h1>
Bastien FREMONDIERE's avatar
Fix bug  
Bastien FREMONDIERE committed
61 62
                    <xsl:value-of select="@TEXT"/>
                    <xsl:value-of select="richcontent"/>
63 64
                </h1>
            </header>
Bastien FREMONDIERE's avatar
Bastien FREMONDIERE committed
65
            <xsl:apply-templates/>
Bastien FREMONDIERE's avatar
Bastien FREMONDIERE committed
66 67
        </xsl:element>
    </xsl:template>
Bastien FREMONDIERE's avatar
Fix bug  
Bastien FREMONDIERE committed
68

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

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

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

Bastien FREMONDIERE's avatar
Bastien FREMONDIERE committed
89
    <!-- Utility functions -->
Bastien FREMONDIERE's avatar
Fix bug  
Bastien FREMONDIERE committed
90

Bastien FREMONDIERE's avatar
Bastien FREMONDIERE committed
91 92
    <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
93
        <xsl:param name="replace" as="xs:string"/>
Bastien FREMONDIERE's avatar
Bastien FREMONDIERE committed
94 95 96 97 98 99 100
        <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
101 102
    </xsl:function>

Bastien FREMONDIERE's avatar
Bastien FREMONDIERE committed
103 104
    <xsl:template name="string-remove-all">
        <xsl:param name="text" as="xs:string"/>
Bastien FREMONDIERE's avatar
Fix bug  
Bastien FREMONDIERE committed
105
        <xsl:param name="replace" as="xs:string"/>
Bastien FREMONDIERE's avatar
Bastien FREMONDIERE committed
106 107
        <xsl:choose>
            <xsl:when test="contains($text, $replace)">
Bastien FREMONDIERE's avatar
Fix bug  
Bastien FREMONDIERE committed
108
                <xsl:value-of select="substring-before($text,$replace)"/>
Bastien FREMONDIERE's avatar
Bastien FREMONDIERE committed
109
                <xsl:call-template name="string-remove-all">
Bastien FREMONDIERE's avatar
Fix bug  
Bastien FREMONDIERE committed
110 111
                    <xsl:with-param name="text" select="substring-after($text,$replace)"/>
                    <xsl:with-param name="replace" select="$replace"/>
Bastien FREMONDIERE's avatar
Bastien FREMONDIERE committed
112 113 114
                </xsl:call-template>
            </xsl:when>
            <xsl:otherwise>
Bastien FREMONDIERE's avatar
Fix bug  
Bastien FREMONDIERE committed
115
                <xsl:value-of select="$text"/>
Bastien FREMONDIERE's avatar
Bastien FREMONDIERE committed
116 117 118
            </xsl:otherwise>
        </xsl:choose>
    </xsl:template>
119
</xsl:stylesheet>