export_sql.xsl 2.98 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:xs="http://www.w3.org/2001/XMLSchema"
    exclude-result-prefixes="xs"
    version="2.0"
    xmlns:sc="http://www.utc.fr/ics/scenari/v3/core"
    xmlns:sp="http://www.utc.fr/ics/scenari/v3/primitive"
    xmlns:of="scpf.org:office" 
    >
    
    <xsl:output method="text"></xsl:output>
    
    <xsl:template match="/sc:item">
14
        <xsl:text>BEGIN;</xsl:text>
Stephane Crozat's avatar
Fix #2  
Stephane Crozat committed
15
        <xsl:text>INSERT INTO api (code,name,description,year,semester,dbegin,dend,size,ects,mail) VALUES</xsl:text>
16
17
        <xsl:apply-templates select="of:webSite/sp:home/of:page/sp:subPage"/>
        ;
18
        <xsl:text>COMMIT;</xsl:text>
19
20
21
22
23
24
25
26
27
28
29
30
    </xsl:template>
    
    <xsl:template match="sp:subPage">
        <xsl:apply-templates select="document(@sc:refUri)/sc:item" mode="api">
            <xsl:with-param name="code">
                <xsl:value-of select="substring(@sc:refUri,string-length(@sc:refUri)-11,4)"/>
            </xsl:with-param>
        </xsl:apply-templates>   
        <xsl:if test="following::sp:subPage">,</xsl:if>
    </xsl:template>
    
    <xsl:template match="sc:item" mode="api">
Stephane Crozat's avatar
Fix #2  
Stephane Crozat committed
31
        <xsl:param name="code"/>        
32
33
34
        <xsl:variable name="title">
            <xsl:value-of select="replace(of:section/of:sectionM/sp:title,'''','''''')"/>
        </xsl:variable>
Stephane Crozat's avatar
Fix #2  
Stephane Crozat committed
35
36
37
        <xsl:variable name="longtitle">
            <xsl:value-of select="replace(.//sp:emphasis[1]//sc:para[1],'''','''''')"/>
        </xsl:variable>
38
        <xsl:variable name="begin">
Stephane Crozat's avatar
Fix #2  
Stephane Crozat committed
39
            <xsl:value-of select="substring(.//sp:info[of:block/of:blockM/sp:title='Période']//sc:para[1],1,5)"/>
40
41
        </xsl:variable>
        <xsl:variable name="end">
Stephane Crozat's avatar
Fix #2  
Stephane Crozat committed
42
            <xsl:value-of select="substring(.//sp:info[of:block/of:blockM/sp:title='Période']//sc:para[1],7,11)"/>
43
44
        </xsl:variable>
        <xsl:variable name="size">
Stephane Crozat's avatar
Fix #2  
Stephane Crozat committed
45
            <xsl:value-of select="number(.//sp:info[of:block/of:blockM/sp:title='Capacité d''accueil']//sc:para[1])"/>
46
47
        </xsl:variable>
        <xsl:variable name="ects">
Stephane Crozat's avatar
Fix #2  
Stephane Crozat committed
48
            <xsl:value-of select="number(.//sp:info[of:block/of:blockM/sp:title='ECTS']//sc:para[1])"/>
49
        </xsl:variable>
50
        <xsl:variable name="mail">
Stephane Crozat's avatar
Fix #2  
Stephane Crozat committed
51
            <xsl:value-of select=".//sp:info[of:block/of:blockM/sp:title='Mail']//sc:para[1]"/>
52
        </xsl:variable>        
53
54
        (
        <xsl:value-of select="$code"/>,
Stephane Crozat's avatar
Fix #2  
Stephane Crozat committed
55
56
        '<xsl:value-of select="$title"></xsl:value-of>',
        '<xsl:value-of select="$longtitle"></xsl:value-of>',        
57
58
59
60
61
        2019,
        'H',
        TO_DATE('<xsl:value-of select="$begin"/>/19','DD/MM/YY'),
        TO_DATE('<xsl:value-of select="$end"/>/19','DD/MM/YY'),
        <xsl:value-of select="$size"/>,
62
63
64
65
66
        <xsl:value-of select="$ects"/>,
        <xsl:choose>
            <xsl:when test="$mail=''">NULL</xsl:when>
            <xsl:otherwise>'<xsl:value-of select="$mail"/>'</xsl:otherwise>
        </xsl:choose>       
67
68
69
70
71
72
        )        
    </xsl:template>
    
    
    
</xsl:stylesheet>