html2xhtml.xsl 2.35 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:xs="http://www.w3.org/2001/XMLSchema" exclude-result-prefixes="xs"
    xmlns:regexp="http://exslt.org/regular-expressions" extension-element-prefixes="regexp">
    
    
    <xsl:output method="xhtml" indent="yes" />
    <xsl:strip-space elements="*"/>
    
    <xsl:param name="text-encoding" as="xs:string" select="'utf-8'"/>
    <xsl:param name="text-uri" as="xs:string"
        select="'file:///C:/Users/Jean-Côme/Documents/Cours/GI05/NF29/TestEtherpad/NF29_HdocEtherpad.html'"/>
    
    <xsl:template name="text2xml">
        <xsl:variable name="text" select="unparsed-text($text-uri, $text-encoding)"/>
        <xsl:analyze-string select="$text" regex=".*title.(.*).title.\n.*\n.*\n.*\n.*\n.*\n.*.body.(.*br.*)..body.">
            <xsl:matching-substring>                
                <head>
                    <title>
                        <xsl:value-of select="normalize-space(regex-group(1))"/>
                    </title>
                    <meta charset="utf-8"/>
                </head>
                <body>             
                    <xsl:value-of select="replace(normalize-space(regex-group(2)), 'br', 'br/')" disable-output-escaping="yes"/>
                </body>
                
            </xsl:matching-substring>
        </xsl:analyze-string>
        
    </xsl:template>
    
    
    <xsl:template match="/">
        <html lang="en">
            <xsl:choose>
                <xsl:when test="unparsed-text-available($text-uri, $text-encoding)">
                    <xsl:call-template name="text2xml"/>
                </xsl:when>
                <xsl:otherwise>
                    <xsl:variable name="error">
                        <xsl:text>Error reading "</xsl:text>
                        <xsl:value-of select="$text-uri"/>
                        <xsl:text>" (encoding "</xsl:text>
                        <xsl:value-of select="$text-encoding"/>
                        <xsl:text>").</xsl:text>
                    </xsl:variable>
                    <xsl:message>
                        <xsl:value-of select="$error"/>
                    </xsl:message>
                    <xsl:value-of select="$error"/>
                </xsl:otherwise>
            </xsl:choose>
        </html>
    </xsl:template>
    
</xsl:stylesheet>