sect.xsl 4.1 KB
Newer Older
1
<?xml version="1.0" encoding="UTF-8"?>
Bastien FREMONDIERE's avatar
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
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
Bastien FREMONDIERE committed
16
                <xsl:apply-templates mode="header"/>
17
            </head>
Bastien FREMONDIERE's avatar
Bastien FREMONDIERE committed
18
            <body>
19 20 21
                <xsl:apply-templates/>
            </body>
        </html>
Bastien FREMONDIERE's avatar
Bastien FREMONDIERE committed
22

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


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

Bastien FREMONDIERE's avatar
Bastien FREMONDIERE committed
34
    <!-- Default behavior for node -->
35
    <xsl:template match="node">
Bastien FREMONDIERE's avatar
Bastien FREMONDIERE committed
36
        <xsl:element name="section">
37 38
            <header>
                <h1>
Bastien FREMONDIERE's avatar
Bastien FREMONDIERE committed
39 40
                    <xsl:value-of select="@TEXT"/>
                    <xsl:value-of select="richcontent"/>
41 42
                </h1>
            </header>
Bastien FREMONDIERE's avatar
Bastien FREMONDIERE committed
43
            <xsl:apply-templates select="node"/>
44 45
        </xsl:element>
    </xsl:template>
Bastien FREMONDIERE's avatar
Bastien FREMONDIERE committed
46

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

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

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

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

Bastien FREMONDIERE's avatar
Bastien FREMONDIERE committed
88
    <!-- Utility functions -->
Bastien FREMONDIERE's avatar
Bastien FREMONDIERE committed
89

Bastien FREMONDIERE's avatar
Bastien FREMONDIERE committed
90 91
    <xsl:function name="utc:string-remove-all" as="xs:string">
        <xsl:param name="text" as="xs:string"/>
Bastien FREMONDIERE's avatar
Bastien FREMONDIERE committed
92
        <xsl:param name="replace" as="xs:string"/>
Bastien FREMONDIERE's avatar
Bastien FREMONDIERE committed
93 94 95 96 97
        <!--
        <xsl:call-template name="string-remove-all">
            <xsl:with-param name="text" select="$text" />
            <xsl:with-param name="replace" select="$replace" />
        </xsl:call-template>-->
Bastien FREMONDIERE's avatar
Bastien FREMONDIERE committed
98 99 100
        <xsl:value-of select="$text"/>
    </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
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
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
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
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>
117
</xsl:stylesheet>