export_sql.xsl 3.42 KB
Newer Older
1 2 3 4 5 6 7
<?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"
8
    xmlns:of="scpf.org:office"
9
    >
10

11
    <xsl:output method="text"></xsl:output>
12 13 14

    <xsl:variable name="year">2020</xsl:variable>

15
    <xsl:variable name="logintitle">Login UTC du responsable UTC</xsl:variable>
16 17 18 19 20 21

    <xsl:template match="/sc:item">
        <xsl:apply-templates select="of:webSite/sp:home/of:page/sp:subPage" mode="login"/>

        <xsl:text>BEGIN;</xsl:text>
        <xsl:apply-templates select="of:webSite/sp:home/of:page/sp:subPage"/>
22
        <xsl:text>COMMIT;</xsl:text>
23
    </xsl:template>
24 25

    <xsl:template match="sp:subPage" mode="login">
26 27
        <xsl:text>INSERT INTO localuser (utclogin) VALUES ('</xsl:text>
        <xsl:value-of select="document(@sc:refUri)/sc:item//sp:info[of:block/of:blockM/sp:title=$logintitle]//sc:para[1]"/>
28
        <xsl:text>');</xsl:text>
29
    </xsl:template>
30

31 32 33 34 35
    <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>
36
        </xsl:apply-templates>
37
    </xsl:template>
38

39
    <xsl:template match="sc:item" mode="api">
40 41
        <xsl:param name="code"/>
        <xsl:variable name="id">gen_random_uuid()</xsl:variable>
42 43 44
        <xsl:variable name="begin">
            <xsl:value-of select="substring(.//sp:info[of:block/of:blockM/sp:title='Période']//sc:para[1],1,5)"/>
        </xsl:variable>
45 46 47
        <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
48 49 50
        <xsl:variable name="longtitle">
            <xsl:value-of select="replace(.//sp:emphasis[1]//sc:para[1],'''','''''')"/>
        </xsl:variable>
51 52 53 54
        <xsl:variable name="duration">
            <xsl:value-of select="
                number(substring(.//sp:info[of:block/of:blockM/sp:title='Période']//sc:para[1],7,2))
                -
55 56
                number(substring(.//sp:info[of:block/of:blockM/sp:title='Période']//sc:para[1],1,2))
                +1
57 58
                "
            />
59 60
        </xsl:variable>
        <xsl:variable name="size">
Stephane Crozat's avatar
Fix #2  
Stephane Crozat committed
61
            <xsl:value-of select="number(.//sp:info[of:block/of:blockM/sp:title='Capacité d''accueil']//sc:para[1])"/>
62 63
        </xsl:variable>
        <xsl:variable name="ects">
Stephane Crozat's avatar
Fix #2  
Stephane Crozat committed
64
            <xsl:value-of select="number(.//sp:info[of:block/of:blockM/sp:title='ECTS']//sc:para[1])"/>
65
        </xsl:variable>
66 67
        <xsl:variable name="login">
            <xsl:value-of select=".//sp:info[of:block/of:blockM/sp:title=$logintitle]//sc:para[1]"/>
68 69
        </xsl:variable>
INSERT INTO api (id,dbegin,code,name,description,duration,size,ects,resplogin) VALUES (
70
<xsl:value-of select="$id"/>,
71
TO_DATE('<xsl:value-of select="$begin"/>/<xsl:value-of select="$year"/>','DD/MM/YYYY'),
72 73
<xsl:value-of select="$code"/>,
'<xsl:value-of select="$title"></xsl:value-of>',
74
'<xsl:value-of select="$longtitle"></xsl:value-of>',
75 76 77
<xsl:value-of select="$duration"/>,
<xsl:value-of select="$size"/>,
<xsl:value-of select="$ects"/>,
78 79
'<xsl:value-of select="$login"/>'
<xsl:text>);</xsl:text>
80
    </xsl:template>
81 82 83 84



</xsl:stylesheet>