export_sql.xsl 3.54 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12
<?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>
    
13 14 15 16 17 18 19
    <xsl:variable name="logintitle">Login UTC du responsable UTC</xsl:variable>
    
    <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"/>        
20
        <xsl:text>COMMIT;</xsl:text>
21 22
    </xsl:template>
    
23 24 25 26 27 28
    <xsl:template match="sp:subPage" mode="login">        
        <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]"/>
        <xsl:text>');</xsl:text>                           
    </xsl:template>
    
29 30 31 32 33
    <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>
34
        </xsl:apply-templates>           
35 36 37
    </xsl:template>
    
    <xsl:template match="sc:item" mode="api">
Stephane Crozat's avatar
Fix #2  
Stephane Crozat committed
38
        <xsl:param name="code"/>        
39
        <xsl:variable name="id">gen_random_uuid()</xsl:variable>        
40 41 42
        <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>
43 44 45
        <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
46 47 48
        <xsl:variable name="longtitle">
            <xsl:value-of select="replace(.//sp:emphasis[1]//sc:para[1],'''','''''')"/>
        </xsl:variable>
49 50 51 52 53 54 55 56
        <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))
                -
                number(substring(.//sp:info[of:block/of:blockM/sp:title='Période']//sc:para[1],1,2)) 
                +1                
                "
            />
57 58
        </xsl:variable>
        <xsl:variable name="size">
Stephane Crozat's avatar
Fix #2  
Stephane Crozat committed
59
            <xsl:value-of select="number(.//sp:info[of:block/of:blockM/sp:title='Capacité d''accueil']//sc:para[1])"/>
60 61
        </xsl:variable>
        <xsl:variable name="ects">
Stephane Crozat's avatar
Fix #2  
Stephane Crozat committed
62
            <xsl:value-of select="number(.//sp:info[of:block/of:blockM/sp:title='ECTS']//sc:para[1])"/>
63
        </xsl:variable>
64 65 66 67 68 69 70 71 72 73 74 75 76 77
        <xsl:variable name="login">
            <xsl:value-of select=".//sp:info[of:block/of:blockM/sp:title=$logintitle]//sc:para[1]"/>
        </xsl:variable>   
INSERT INTO api (id,dbegin,code,name,description,duration,size,ects,resplogin) VALUES (        
<xsl:value-of select="$id"/>,
TO_DATE('<xsl:value-of select="$begin"/>/19','DD/MM/YY'),
<xsl:value-of select="$code"/>,
'<xsl:value-of select="$title"></xsl:value-of>',
'<xsl:value-of select="$longtitle"></xsl:value-of>',        
<xsl:value-of select="$duration"/>,
<xsl:value-of select="$size"/>,
<xsl:value-of select="$ects"/>,
'<xsl:value-of select="$login"/>'             
<xsl:text>);</xsl:text>        
78 79 80 81 82
    </xsl:template>
    
    
    
</xsl:stylesheet>