<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns="http://www.sistory.si/schemas/sistory-ar/"
    xmlns:sistory="http://www.sistory.si/schemas/sistory-ar/"
    xmlns:junaio="http://dev.junaio.com/index/mychannels"
    xmlns:layar="http://www.layar.com/documentation/browser/"
    xmlns:arel="http://www.junaio.com/develop/docs/arel-xml-schema/"
    xmlns:kml="http://www.opengis.net/kml/2.2"
    xmlns:ar="http://www.openarml.org/arml/1.0"
    xmlns:wikitude="http://www.openarml.org/wikitude/1.0"
    xmlns:dc="http://purl.org/dc/elements/1.1/"
    version="2.0"
    exclude-result-prefixes="sistory">
    <!-- pretvorba sistory-ar XML v SQL za Layar MySQL
         Vsak jezik ima svojo MySQL bazo.
    -->
    
    <doc xmlns="http://www.oxygenxml.com/ns/doc/xsl" scope="stylesheet" type="stylesheet">
        <desc>
            <p>SIstory augmented reality stylesheet for converting SIstory augmented reality XML to Layar SQL.</p>
            <p>This software is dual-licensed:
                
                1. Distributed under a Creative Commons Attribution-ShareAlike 3.0
                Unported License http://creativecommons.org/licenses/by-sa/3.0/ 
                
                2. http://www.opensource.org/licenses/BSD-2-Clause
                
                All rights reserved.
                
                Redistribution and use in source and binary forms, with or without
                modification, are permitted provided that the following conditions are
                met:
                
                * Redistributions of source code must retain the above copyright
                notice, this list of conditions and the following disclaimer.
                
                * Redistributions in binary form must reproduce the above copyright
                notice, this list of conditions and the following disclaimer in the
                documentation and/or other materials provided with the distribution.
                
                This software is provided by the copyright holders and contributors
                "as is" and any express or implied warranties, including, but not
                limited to, the implied warranties of merchantability and fitness for
                a particular purpose are disclaimed. In no event shall the copyright
                holder or contributors be liable for any direct, indirect, incidental,
                special, exemplary, or consequential damages (including, but not
                limited to, procurement of substitute goods or services; loss of use,
                data, or profits; or business interruption) however caused and on any
                theory of liability, whether in contract, strict liability, or tort
                (including negligence or otherwise) arising in any way out of the use
                of this software, even if advised of the possibility of such damage.
            </p>
            <p xml:lang="en">Andrej Pančur, Institute of contemporary History, Ljubljana</p>
            <p xml:lang="sl">Andrej Pančur, Inštitut za novejšo zgodovino, Ljubljana</p>
            <p>2013-10-10</p>
        </desc>
    </doc>
    
    <xsl:param name="imageResize100"><xsl:text disable-output-escaping="yes"><![CDATA[&width=100&height=75]]></xsl:text></xsl:param>
    
    <xsl:output method="text" omit-xml-declaration="yes" indent="no"/>
    <xsl:strip-space elements="*"/>
    
    <xsl:param name="delimeterHeader" select="','"/>
    <xsl:param name="startValue">(</xsl:param>
    <xsl:param name="endValue">),</xsl:param>
    <xsl:param name="endValues">);</xsl:param>
    <xsl:param name="delString">'</xsl:param>
    <xsl:param name="delValue" select="', '"/>
    
    <!-- Za vsak jezik posebej določene oznake za elektronsko pošto, poezavo na spletno stran in telefon. -->
    <xsl:variable name="emailLabel">
        <label lang="slv">e-mail</label>
        <label lang="eng">Email</label>
        <label lang="deu">E-Mail</label>
    </xsl:variable>
    <xsl:variable name="linkLabel">
        <label lang="slv">Povezava</label>
        <label lang="eng">Webpage</label>
        <label lang="deu">Webseite</label>
    </xsl:variable>
    <xsl:variable name="phoneLabel">
        <label lang="slv">Telefon</label>
        <label lang="eng">Phone</label>
        <label lang="deu">Telefon</label>
    </xsl:variable>
    
    <xsl:variable name="count-poi">
        <xsl:value-of select="count(//sistory:poi)"/>
    </xsl:variable>
    
    <xsl:variable name="headers_POI">
        <header>`id`</header>
        <header>`footnote`</header>
        <header>`title`</header>
        <header>`lat`</header>
        <header>`lon`</header>
        <header>`imageURL`</header>
        <header>`description`</header>
        <header>`biwStyle`</header>
        <header>`alt`</header>
        <header>`doNotIndex`</header>
        <header>`showSmallBiw`</header>
        <header>`showBiwOnClick`</header>
        <header>`poiType`</header>
        <header>`layerID`</header>
    </xsl:variable>
    
    <xsl:variable name="headers_POIAction">
        <header>`poiID`</header>
        <header>`label`</header>
        <header>`uri`</header>
        <header>`autoTriggerRange`</header>
        <header>`autoTriggerOnly`</header>
        <header>`id`</header>
        <header>`contentType`</header>
        <header>`method`</header>
        <header>`activityType`</header>
        <header>`params`</header>
        <header>`closeBiw`</header>
        <header>`showActivity`</header>
        <header>`activityMessage`</header>
        <header>`autoTrigger`</header>
    </xsl:variable>
    
    <xsl:template match="/">
        <xsl:for-each select="sistory:AR/sistory:providerINFO/sistory:layar/sistory:admin/layar:layerTitle">
            <xsl:variable name="language" select="@lang"/>
            <xsl:variable name="document">
                <xsl:value-of select="concat('layar-',$language,'.sql')"/>
            </xsl:variable>
            <xsl:result-document href="{$document}">
                <!-- POIs GLAVA -->
                <xsl:text>INSERT INTO `POI` (</xsl:text>
                <xsl:value-of select="$headers_POI/sistory:header" separator="{$delimeterHeader}"/>
                <xsl:text>) VALUES</xsl:text>
                <xsl:text>&#xa;</xsl:text>
                <!-- TOČKE INTERESA POI -->
                <!-- samo tiste, ki so aktivne - se pravi, da je boolean vrednost atributa active true -->
                <xsl:for-each select="ancestor::sistory:AR/sistory:POIs/sistory:poi[@active=true()]">
                    <!-- id -->
                    <xsl:value-of select="concat($startValue,$delString,@id,$delString,$delValue)"/>
                    <!-- footnote -->
                    <xsl:choose>
                        <xsl:when test="sistory:text/layar:footnote[@lang = $language]">
                            <xsl:value-of select="concat($delString,sistory:text/layar:footnote[@lang = $language],$delString,$delValue)"/>
                        </xsl:when>
                        <xsl:otherwise>
                            <xsl:value-of select="concat($delString,ancestor::sistory:AR/sistory:providerINFO/sistory:layar/sistory:xml/layar:footnote[@lang='deu'],$delString,$delValue)"/>
                        </xsl:otherwise>
                    </xsl:choose>
                    <!-- title -->
                    <xsl:value-of select="concat($delString,sistory:text/layar:title[@lang = $language],$delString,$delValue)"/>
                    <!-- lat -->
                    <xsl:value-of select="concat($delString,sistory:location/sistory:lat,$delString,$delValue)"/>
                    <!-- lon -->
                    <xsl:value-of select="concat($delString,sistory:location/sistory:lon,$delString,$delValue)"/>
                    <!-- imageURL -->
                    <xsl:choose>
                        <xsl:when test="sistory:images/sistory:image[1]/sistory:imageResize/sistory:path">
                            <xsl:value-of select="concat($delString,sistory:images/sistory:image[1]/sistory:imageResize/sistory:path,$imageResize100,$delString,$delValue)"/>
                        </xsl:when>
                        <xsl:when test="sistory:images/sistory:image[1]/sistory:imageResize/sistory:imageID">
                            <xsl:value-of select="concat($delString,ancestor::sistory:AR/sistory:providerINFO/sistory:imageResizePath,sistory:images/sistory:image[1]/sistory:imageResize/sistory:imageID,$imageResize100,$delString,$delValue)"/>
                        </xsl:when>
                        <xsl:otherwise>
                            <xsl:value-of select="concat($delString,sistory:images/sistory:image[1]/layar:imageURL,$delString,$delValue)"/>
                        </xsl:otherwise>
                    </xsl:choose>
                    <!-- description -->
                    <xsl:value-of select="concat($delString,normalize-space(sistory:text/layar:description[@lang = $language]),$delString,$delValue)"/>
                    <!-- biwStyle -->
                    <xsl:value-of select="concat($delString,'classic',$delString,$delValue)"/>
                    <!-- alt -->
                    <xsl:choose>
                        <xsl:when test="sistory:location/sistory:alt">
                            <xsl:value-of select="concat($delString,sistory:location/sistory:alt,$delString,$delValue)"/>
                        </xsl:when>
                        <xsl:otherwise>
                            <xsl:text>NULL</xsl:text><xsl:value-of select="$delValue"/>
                        </xsl:otherwise>
                    </xsl:choose>
                    <!-- doNotIndex -->
                    <xsl:text>0</xsl:text><xsl:value-of select="$delValue"/>
                    <!-- showSmallBiw -->
                    <xsl:text>1</xsl:text><xsl:value-of select="$delValue"/>
                    <!-- showBiwOnClick -->
                    <xsl:text>1</xsl:text><xsl:value-of select="$delValue"/>
                    <!-- poiType -->
                    <xsl:text>'geo'</xsl:text><xsl:value-of select="$delValue"/>
                    <!-- layerID -->
                    <xsl:value-of select="ancestor::sistory:AR/sistory:providerINFO/sistory:layar/sistory:admin/layar:layer[@lang = $language]/@n"/>
                    <!-- zaključna vejica (če POI ni zaden) ali podpičje (če je POI zaden) -->
                    <xsl:choose>
                        <xsl:when test="position() eq last()">
                            <xsl:text>);&#xa;&#xa;</xsl:text>
                        </xsl:when>
                        <xsl:otherwise>
                            <xsl:text>),&#xa;</xsl:text>
                        </xsl:otherwise>
                    </xsl:choose>
                </xsl:for-each>
                
                <!-- ACTIONS (trentno BREZ povezave na zunanjo, avtomatično izdelano spletno stran -->
                <!-- Najprej se preveri, če imajo točke interesa sploh akcije, ki so primerne za Layar. -->
                <xsl:if test="ancestor::sistory:AR/sistory:POIs/sistory:poi/sistory:actions/sistory:email or
                              ancestor::sistory:AR/sistory:POIs/sistory:poi/sistory:actions/sistory:link or
                              ancestor::sistory:AR/sistory:POIs/sistory:poi/sistory:actions/sistory:linksGroup or
                              ancestor::sistory:AR/sistory:POIs/sistory:poi/sistory:actions/sistory:phone">
                    <!-- ACTIONS GLAVA -->
                    <xsl:text>INSERT INTO `POIAction` (</xsl:text>
                    <xsl:value-of select="$headers_POIAction/sistory:header" separator="{$delimeterHeader}"/>
                    <xsl:text>) VALUES</xsl:text>
                    <xsl:text>&#xa;</xsl:text>
                    <!-- TOČKE INTERESA POI -->
                    <!-- samo tiste, ki so aktivne  - se pravi, da je boolean vrednost atributa active true -->
                    <xsl:for-each select="ancestor::sistory:AR/sistory:POIs/sistory:poi[@active=true()]">
                        <!-- Preveri, kateri po vrsti je trenutni POI, nato pa prišteje številko 1,
                             da lahko nato preveri, če ima kateri od POI, ki sledijo trenutnemu, določene elemente. -->
                        <xsl:variable name="levelOfPOI">
                            <xsl:number count="sistory:poi" level="any"/>
                        </xsl:variable>
                        <xsl:variable name="numberOfPOI">
                            <xsl:number value="$levelOfPOI + 1"/>
                        </xsl:variable>
                        <!-- email -->
                        <xsl:for-each select="sistory:actions/sistory:email">
                            <xsl:variable name="actionID">
                                <xsl:number count="sistory:email | sistory:actions/sistory:link | sistory:linksGroup | sistory:linkPOIWebpage | sistory:phone" level="any"/>
                            </xsl:variable>
                            <!-- poiID -->
                            <xsl:value-of select="concat($startValue,$delString,ancestor::sistory:poi/@id,$delString,$delValue)"/>
                            <!-- label -->
                            <xsl:value-of select="concat($delString,$emailLabel/sistory:label[@lang = $language],$delString,$delValue)"/>
                            <!-- uri -->
                            <xsl:value-of select="concat($delString,'mailto:',.,$delString,$delValue)"/>
                            <!-- autoTriggerRange -->
                            <xsl:text>NULL</xsl:text><xsl:value-of select="$delValue"/>
                            <!-- autoTriggerOnly -->
                            <xsl:text>1</xsl:text><xsl:value-of select="$delValue"/>
                            <!-- id - MORA BITI AUTO-INCREMENT -->
                            <xsl:number value="$actionID"/><xsl:value-of select="$delValue"/>
                            <!-- contentType -->
                            <xsl:text>'application/vnd.layar.internal'</xsl:text><xsl:value-of select="$delValue"/>
                            <!-- method -->
                            <xsl:text>'GET'</xsl:text><xsl:value-of select="$delValue"/>
                            <!-- activityType določa, katere vrste je akcija. Za elektronsko pošto je 5 -->
                            <xsl:text>5</xsl:text><xsl:value-of select="$delValue"/>
                            <!-- params -->
                            <xsl:text>NULL</xsl:text><xsl:value-of select="$delValue"/>
                            <!-- closeBiw -->
                            <xsl:text>0</xsl:text><xsl:value-of select="$delValue"/>
                            <!-- showActivity -->
                            <xsl:text>1</xsl:text><xsl:value-of select="$delValue"/>
                            <!-- activityMessage -->
                            <xsl:text>'Pošlji sporočilo'</xsl:text><xsl:value-of select="$delValue"/>
                            <!-- autoTrigger -->
                            <xsl:text>0</xsl:text>
                            <!-- Zaključno ločilo: Preveri ali katera od naslednjih (variabla numberOfPOI da zaporedni vrstni red
                                 trenutne POI, kateri prišteje številko ena) točk interesa poi in nato vse do konca (variabla count-poi prešteje
                                 vse aktivne poi) vsebuje tudi podatek za email.
                                 Nato preveri, če sta skupaj z njo še kakšna povezava, skupina povezav ali telefonska številka.
                               -->
                            <xsl:choose>
                                <xsl:when test="ancestor::sistory:POIs/sistory:poi[position() = ($numberOfPOI to $count-poi)]/sistory:actions/sistory:email or 
                                    ancestor::sistory:POIs/sistory:poi[position() = ($numberOfPOI to $count-poi)]/sistory:actions/sistory:link or
                                    ancestor::sistory:POIs/sistory:poi[position() = ($numberOfPOI to $count-poi)]/sistory:actions/sistory:linksGroup or
                                    ancestor::sistory:POIs/sistory:poi[position() = ($numberOfPOI to $count-poi)]/sistory:actions/sistory:phone or
                                    parent::sistory:actions/sistory:link or
                                    parent::sistory:actions/sistory:linksGroup or
                                    parent::sistory:actions/sistory:phone">
                                    <xsl:text>),&#xa;</xsl:text>
                                </xsl:when>
                                <xsl:otherwise>
                                    <xsl:text>);&#xa;&#xa;</xsl:text>
                                </xsl:otherwise>
                            </xsl:choose>
                        </xsl:for-each>
                        
                        <!-- spletna stran -->
                        <!-- Vsaka jezikovna varianta dobi povezavo na to spletno stran. -->
                        <xsl:for-each select="sistory:actions/sistory:link">
                            <xsl:variable name="actionID">
                                <xsl:number count="sistory:email | sistory:actions/sistory:link | sistory:linksGroup | sistory:linkPOIWebpage | sistory:phone" level="any"/>
                            </xsl:variable>    
                            <!-- poiID -->
                            <xsl:value-of select="concat($startValue,$delString,ancestor::sistory:poi/@id,$delString,$delValue)"/>
                            <!-- label -->
                            <xsl:value-of select="concat($delString,$linkLabel/sistory:label[@lang = $language],$delString,$delValue)"/>
                            <!-- uri -->
                            <xsl:value-of select="concat($delString,.,$delString,$delValue)"/>
                            <!-- autoTriggerRange -->
                            <xsl:text>NULL</xsl:text><xsl:value-of select="$delValue"/>
                            <!-- autoTriggerOnly -->
                            <xsl:text>1</xsl:text><xsl:value-of select="$delValue"/>
                            <!-- id - MORA BITI AUTO-INCREMENT -->
                            <xsl:number value="$actionID"/><xsl:value-of select="$delValue"/>
                            <!-- contentType -->
                            <xsl:text>'text/html'</xsl:text><xsl:value-of select="$delValue"/>
                            <!-- method -->
                            <xsl:text>'GET'</xsl:text><xsl:value-of select="$delValue"/>
                            <!-- activityType določa, katere vrste je akcija. Za spletno stran je 1 -->
                            <xsl:text>1</xsl:text><xsl:value-of select="$delValue"/>
                            <!-- params -->
                            <xsl:text>'lat,lon,alt,lang,countrycode,localCountryCode,version'</xsl:text><xsl:value-of select="$delValue"/>
                            <!-- closeBiw -->
                            <xsl:text>0</xsl:text><xsl:value-of select="$delValue"/>
                            <!-- showActivity -->
                            <xsl:text>1</xsl:text><xsl:value-of select="$delValue"/>
                            <!-- activityMessage -->
                            <xsl:text>NULL</xsl:text><xsl:value-of select="$delValue"/>
                            <!-- autoTrigger -->
                            <xsl:text>0</xsl:text>
                            <!-- zaključna ločila -->
                            <xsl:choose>
                                <xsl:when test="ancestor::sistory:POIs/sistory:poi[position() = ($numberOfPOI to $count-poi)]/sistory:actions/sistory:email or 
                                    ancestor::sistory:POIs/sistory:poi[position() = ($numberOfPOI to $count-poi)]/sistory:actions/sistory:link or
                                    ancestor::sistory:POIs/sistory:poi[position() = ($numberOfPOI to $count-poi)]/sistory:actions/sistory:linksGroup or
                                    ancestor::sistory:POIs/sistory:poi[position() = ($numberOfPOI to $count-poi)]/sistory:actions/sistory:phone or
                                    parent::sistory:actions/sistory:linksGroup or
                                    parent::sistory:actions/sistory:phone">
                                    <xsl:text>),&#xa;</xsl:text>
                                </xsl:when>
                                <xsl:otherwise>
                                    <xsl:text>);&#xa;&#xa;</xsl:text>
                                </xsl:otherwise>
                            </xsl:choose>
                        </xsl:for-each>
                        <!-- Če je več jezikovnih variant posamezne spletne strani, se jezikovnim variantam Junaio aplikacije
                             določajo glede na podatek o jeziku in sicer po sledečih prioritetah:
                             - če obstaja spletna stran z istim jezikom kot aplikacija, se da to spletno stran,
                             - če ne obstaja spletna stran z istim jezikom kot aplikacija, se da angleško spletno stran,
                             - če ne obstaja angleška spletna stran, se da slovensko spletno stran.
                          -->
                        <xsl:for-each select="sistory:actions/sistory:linksGroup">
                            <xsl:variable name="actionID">
                                <xsl:number count="sistory:email | sistory:actions/sistory:link | sistory:linksGroup | sistory:linkPOIWebpage | sistory:phone" level="any"/>
                            </xsl:variable>
                            <xsl:choose>
                                <xsl:when test="sistory:link[@lang = $language]">
                                    <!-- poiID -->
                                    <xsl:value-of select="concat($startValue,$delString,ancestor::sistory:poi/@id,$delString,$delValue)"/>
                                    <!-- label -->
                                    <xsl:value-of select="concat($delString,$linkLabel/sistory:label[@lang = $language],$delString,$delValue)"/>
                                    <!-- uri -->
                                    <xsl:value-of select="concat($delString,sistory:link[@lang = $language],$delString,$delValue)"/>
                                    <!-- autoTriggerRange -->
                                    <xsl:text>NULL</xsl:text><xsl:value-of select="$delValue"/>
                                    <!-- autoTriggerOnly -->
                                    <xsl:text>1</xsl:text><xsl:value-of select="$delValue"/>
                                    <!-- id - MORA BITI AUTO-INCREMENT -->
                                    <xsl:number value="$actionID"/><xsl:value-of select="$delValue"/>
                                    <!-- contentType -->
                                    <xsl:text>'text/html'</xsl:text><xsl:value-of select="$delValue"/>
                                    <!-- method -->
                                    <xsl:text>'GET'</xsl:text><xsl:value-of select="$delValue"/>
                                    <!-- activityType določa, katere vrste je akcija. Za spletno stran je 1 -->
                                    <xsl:text>1</xsl:text><xsl:value-of select="$delValue"/>
                                    <!-- params -->
                                    <xsl:text>'lat,lon,alt,lang,countrycode,localCountryCode,version'</xsl:text><xsl:value-of select="$delValue"/>
                                    <!-- closeBiw -->
                                    <xsl:text>0</xsl:text><xsl:value-of select="$delValue"/>
                                    <!-- showActivity -->
                                    <xsl:text>1</xsl:text><xsl:value-of select="$delValue"/>
                                    <!-- activityMessage -->
                                    <xsl:text>NULL</xsl:text><xsl:value-of select="$delValue"/>
                                    <!-- autoTrigger -->
                                    <xsl:text>0</xsl:text>
                                    <!-- zaključna ločila -->
                                    <xsl:choose>
                                        <xsl:when test="ancestor::sistory:POIs/sistory:poi[position() = ($numberOfPOI to $count-poi)]/sistory:actions/sistory:email or 
                                            ancestor::sistory:POIs/sistory:poi[position() = ($numberOfPOI to $count-poi)]/sistory:actions/sistory:link or
                                            ancestor::sistory:POIs/sistory:poi[position() = ($numberOfPOI to $count-poi)]/sistory:actions/sistory:linksGroup or
                                            ancestor::sistory:POIs/sistory:poi[position() = ($numberOfPOI to $count-poi)]/sistory:actions/sistory:phone or
                                            parent::sistory:actions/sistory:phone">
                                            <xsl:text>),&#xa;</xsl:text>
                                        </xsl:when>
                                        <xsl:otherwise>
                                            <xsl:text>);&#xa;&#xa;</xsl:text>
                                        </xsl:otherwise>
                                    </xsl:choose>
                                </xsl:when>
                                <!-- če obstaja angleška spletna stran -->
                                <xsl:otherwise>
                                    <xsl:choose>
                                        <xsl:when test="sistory:link[@lang != $language]
                                                    and sistory:link[@lang='eng']">
                                            <!-- poiID -->
                                            <xsl:value-of select="concat($startValue,$delString,ancestor::sistory:poi/@id,$delString,$delValue)"/>
                                            <!-- label -->
                                            <xsl:value-of select="concat($delString,$linkLabel/sistory:label[@lang = $language],$delString,$delValue)"/>
                                            <!-- uri -->
                                            <xsl:value-of select="concat($delString,sistory:link[@lang='eng'],$delString,$delValue)"/>
                                            <!-- autoTriggerRange -->
                                            <xsl:text>NULL</xsl:text><xsl:value-of select="$delValue"/>
                                            <!-- autoTriggerOnly -->
                                            <xsl:text>1</xsl:text><xsl:value-of select="$delValue"/>
                                            <!-- id - MORA BITI AUTO-INCREMENT -->
                                            <xsl:number value="$actionID"/><xsl:value-of select="$delValue"/>
                                            <!-- contentType -->
                                            <xsl:text>'text/html'</xsl:text><xsl:value-of select="$delValue"/>
                                            <!-- method -->
                                            <xsl:text>'GET'</xsl:text><xsl:value-of select="$delValue"/>
                                            <!-- activityType določa, katere vrste je akcija. Za spletno stran je 1 -->
                                            <xsl:text>1</xsl:text><xsl:value-of select="$delValue"/>
                                            <!-- params -->
                                            <xsl:text>'lat,lon,alt,lang,countrycode,localCountryCode,version'</xsl:text><xsl:value-of select="$delValue"/>
                                            <!-- closeBiw -->
                                            <xsl:text>0</xsl:text><xsl:value-of select="$delValue"/>
                                            <!-- showActivity -->
                                            <xsl:text>1</xsl:text><xsl:value-of select="$delValue"/>
                                            <!-- activityMessage -->
                                            <xsl:text>NULL</xsl:text><xsl:value-of select="$delValue"/>
                                            <!-- autoTrigger -->
                                            <xsl:text>0</xsl:text>
                                            <!-- zaključna ločila -->
                                            <xsl:choose>
                                                <xsl:when test="ancestor::sistory:POIs/sistory:poi[position() = ($numberOfPOI to $count-poi)]/sistory:actions/sistory:email or 
                                                    ancestor::sistory:POIs/sistory:poi[position() = ($numberOfPOI to $count-poi)]/sistory:actions/sistory:link or
                                                    ancestor::sistory:POIs/sistory:poi[position() = ($numberOfPOI to $count-poi)]/sistory:actions/sistory:linksGroup or
                                                    ancestor::sistory:POIs/sistory:poi[position() = ($numberOfPOI to $count-poi)]/sistory:actions/sistory:phone or
                                                    parent::sistory:actions/sistory:phone">
                                                    <xsl:text>),&#xa;</xsl:text>
                                                </xsl:when>
                                                <xsl:otherwise>
                                                    <xsl:text>);&#xa;&#xa;</xsl:text>
                                                </xsl:otherwise>
                                            </xsl:choose>
                                        </xsl:when>
                                        <xsl:otherwise>
                                            <!-- predpostavlja se, da je ena spletna stran vedno v slovenščini -->
                                            <!-- poiID -->
                                            <xsl:value-of select="concat($startValue,$delString,ancestor::sistory:poi/@id,$delString,$delValue)"/>
                                            <!-- label -->
                                            <xsl:value-of select="concat($delString,$linkLabel/sistory:label[@lang = $language],$delString,$delValue)"/>
                                            <!-- uri -->
                                            <xsl:value-of select="concat($delString,sistory:link[@lang='slv'],$delString,$delValue)"/>
                                            <!-- autoTriggerRange -->
                                            <xsl:text>NULL</xsl:text><xsl:value-of select="$delValue"/>
                                            <!-- autoTriggerOnly -->
                                            <xsl:text>1</xsl:text><xsl:value-of select="$delValue"/>
                                            <!-- id - MORA BITI AUTO-INCREMENT -->
                                            <xsl:number value="$actionID"/><xsl:value-of select="$delValue"/>
                                            <!-- contentType -->
                                            <xsl:text>'text/html'</xsl:text><xsl:value-of select="$delValue"/>
                                            <!-- method -->
                                            <xsl:text>'GET'</xsl:text><xsl:value-of select="$delValue"/>
                                            <!-- activityType določa, katere vrste je akcija. Za spletno stran je 1 -->
                                            <xsl:text>1</xsl:text><xsl:value-of select="$delValue"/>
                                            <!-- params -->
                                            <xsl:text>'lat,lon,alt,lang,countrycode,localCountryCode,version'</xsl:text><xsl:value-of select="$delValue"/>
                                            <!-- closeBiw -->
                                            <xsl:text>0</xsl:text><xsl:value-of select="$delValue"/>
                                            <!-- showActivity -->
                                            <xsl:text>1</xsl:text><xsl:value-of select="$delValue"/>
                                            <!-- activityMessage -->
                                            <xsl:text>NULL</xsl:text><xsl:value-of select="$delValue"/>
                                            <!-- autoTrigger -->
                                            <xsl:text>0</xsl:text>
                                            <!-- zaključna ločila -->
                                            <xsl:choose>
                                                <xsl:when test="ancestor::sistory:POIs/sistory:poi[position() = ($numberOfPOI to $count-poi)]/sistory:actions/sistory:email or 
                                                    ancestor::sistory:POIs/sistory:poi[position() = ($numberOfPOI to $count-poi)]/sistory:actions/sistory:link or
                                                    ancestor::sistory:POIs/sistory:poi[position() = ($numberOfPOI to $count-poi)]/sistory:actions/sistory:linksGroup or
                                                    ancestor::sistory:POIs/sistory:poi[position() = ($numberOfPOI to $count-poi)]/sistory:actions/sistory:phone or
                                                    parent::sistory:actions/sistory:phone">
                                                    <xsl:text>),&#xa;</xsl:text>
                                                </xsl:when>
                                                <xsl:otherwise>
                                                    <xsl:text>);&#xa;&#xa;</xsl:text>
                                                </xsl:otherwise>
                                            </xsl:choose>
                                        </xsl:otherwise>
                                    </xsl:choose>
                                </xsl:otherwise>
                            </xsl:choose>
                        </xsl:for-each>
                        
                        <!-- telefon -->
                        <xsl:for-each select="sistory:actions/sistory:phone">
                            <xsl:variable name="actionID">
                                <xsl:number count="sistory:email | sistory:actions/sistory:link | sistory:linksGroup | sistory:linkPOIWebpage | sistory:phone" level="any"/>
                            </xsl:variable>
                            <!-- poiID -->
                            <xsl:value-of select="concat($startValue,$delString,ancestor::sistory:poi/@id,$delString,$delValue)"/>
                            <!-- label -->
                            <xsl:value-of select="concat($delString,$phoneLabel/sistory:label[@lang = $language],$delString,$delValue)"/>
                            <!-- uri -->
                            <xsl:value-of select="concat($delString,'tel:',.,$delString,$delValue)"/>
                            <!-- autoTriggerRange -->
                            <xsl:text>NULL</xsl:text><xsl:value-of select="$delValue"/>
                            <!-- autoTriggerOnly -->
                            <xsl:text>1</xsl:text><xsl:value-of select="$delValue"/>
                            <!-- id - MORA BITI AUTO-INCREMENT -->
                            <xsl:number value="$actionID"/><xsl:value-of select="$delValue"/>
                            <!-- contentType -->
                            <xsl:text>'application/vnd.layar.internal'</xsl:text><xsl:value-of select="$delValue"/>
                            <!-- method -->
                            <xsl:text>'POST'</xsl:text><xsl:value-of select="$delValue"/>
                            <!-- activityType določa, katere vrste je akcija. Za telefon je 4 -->
                            <xsl:text>4</xsl:text><xsl:value-of select="$delValue"/>
                            <!-- params -->
                            <xsl:text>NULL</xsl:text><xsl:value-of select="$delValue"/>
                            <!-- closeBiw -->
                            <xsl:text>0</xsl:text><xsl:value-of select="$delValue"/>
                            <!-- showActivity -->
                            <xsl:text>0</xsl:text><xsl:value-of select="$delValue"/>
                            <!-- activityMessage -->
                            <xsl:text>NULL</xsl:text><xsl:value-of select="$delValue"/>
                            <!-- autoTrigger -->
                            <xsl:text>0</xsl:text>
                            <!-- Zaključno ločilo: Preveri ali katera od naslednjih (variabla numberOfPOI da zaporedni vrstni red
                                 trenutne POI, kateri prišteje 1) točk interesa poi in nato vse do konca (variabla count-poi prešteje
                                 vse aktivne poi) vsebuje tudi podatek za email.
                              -->
                            <xsl:choose>
                                <xsl:when test="ancestor::sistory:POIs/sistory:poi[position() = ($numberOfPOI to $count-poi)]/sistory:actions/sistory:email or
                                    ancestor::sistory:POIs/sistory:poi[position() = ($numberOfPOI to $count-poi)]/sistory:actions/sistory:link or 
                                    ancestor::sistory:POIs/sistory:poi[position() = ($numberOfPOI to $count-poi)]/sistory:actions/sistory:phone">
                                    <xsl:text>),&#xa;</xsl:text>
                                </xsl:when>
                                <xsl:otherwise>
                                    <xsl:text>);&#xa;&#xa;</xsl:text>
                                </xsl:otherwise>
                            </xsl:choose>
                        </xsl:for-each>
                    </xsl:for-each>    
                </xsl:if>
                
            </xsl:result-document>
        </xsl:for-each>
    </xsl:template>
    
</xsl:stylesheet>