Files
kupshop/admin/templates/import/generic.xslt
2025-08-02 16:30:27 +02:00

456 lines
19 KiB
HTML

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<SHOP>
<xsl:for-each select="xml/item">
<xsl:variable name="code">
<xsl:value-of select="current()/kod"/>
</xsl:variable>
<xsl:variable name="oldCode">
<xsl:value-of select="preceding-sibling::*[1]/kod"/>
</xsl:variable>
<xsl:if test="(string-length($code) > 0 and not($code = $oldCode)) or string-length(ean) > 0">
<SHOPITEM convert_to_variation="1">
<xsl:if test="string-length($code) > 0">
<CODE>
<xsl:value-of select="$code"/>
</CODE>
<PRODUCT_CODE>
<xsl:value-of select="$code"/>
</PRODUCT_CODE>
</xsl:if>
<xsl:if test="nazev">
<PRODUCT force="1">
<xsl:value-of select="nazev"/>
</PRODUCT>
</xsl:if>
<xsl:if test="kategorie">
<CATEGORY force="1">
<xsl:value-of select="kategorie"/>
</CATEGORY>
</xsl:if>
<xsl:if test="popis-1">
<SHORT_DESCRIPTION>
<xsl:value-of select="popis-1"/>
</SHORT_DESCRIPTION>
</xsl:if>
<xsl:if test="anotace">
<SHORT_DESCRIPTION>
<xsl:value-of select="anotace"/>
</SHORT_DESCRIPTION>
</xsl:if>
<xsl:if test="popis-2">
<DESCRIPTION>
<xsl:value-of select="popis-2"/>
</DESCRIPTION>
</xsl:if>
<xsl:if test="popis">
<DESCRIPTION>
<xsl:value-of select="popis"/>
</DESCRIPTION>
</xsl:if>
<xsl:if test="seo-titulek">
<META_TITLE>
<xsl:value-of select="seo-titulek"/>
</META_TITLE>
</xsl:if>
<xsl:if test="seo-popis">
<META_DESCRIPTION>
<xsl:value-of select="seo-popis"/>
</META_DESCRIPTION>
</xsl:if>
<xsl:if test="parametry">
<PARAMETERS>
<xsl:value-of select="parametry"/>
</PARAMETERS>
</xsl:if>
<xsl:call-template name="getPrice"/>
<xsl:call-template name="getCommonPrice"/>
<xsl:call-template name="getPriceBuy"/>
<xsl:call-template name="getVat"/>
<xsl:call-template name="getDiscount"/>
<xsl:call-template name="getPriceList"/>
<xsl:call-template name="getLinks"/>
<xsl:if test="vyrobce">
<PRODUCER>
<xsl:value-of select="vyrobce"/>
</PRODUCER>
</xsl:if>
<xsl:if test="zaruka-mes">
<WARRANTY>
<xsl:value-of select="zaruka-mes"/>
</WARRANTY>
</xsl:if>
<xsl:if test="hmotnost-kg">
<WEIGHT>
<xsl:value-of select="hmotnost-kg"/>
</WEIGHT>
</xsl:if>
<xsl:if test="sirka-cm">
<WIDTH>
<xsl:value-of select="sirka-cm"/>
</WIDTH>
</xsl:if>
<xsl:if test="vyska-cm">
<HEIGHT>
<xsl:value-of select="vyska-cm"/>
</HEIGHT>
</xsl:if>
<xsl:if test="hloubka-cm">
<DEPTH>
<xsl:value-of select="hloubka-cm"/>
</DEPTH>
</xsl:if>
<xsl:if test="zobrazovat-ve-srovnavacich">
<SHOW_IN_FEED>
<xsl:if test="string(zobrazovat-ve-srovnavacich) = 'ne'">N</xsl:if>
<xsl:if test="not(string(zobrazovat-ve-srovnavacich) = 'ne')">Y</xsl:if>
</SHOW_IN_FEED>
</xsl:if>
<xsl:if test="zobrazovat-zbozi">
<xsl:variable name="showProduct" select="normalize-space(string(zobrazovat-zbozi))"/>
<HIDDEN>
<xsl:if test="$showProduct = 'ne'">Y</xsl:if>
<xsl:if test="$showProduct = 'ukončen'">O</xsl:if>
<xsl:if test="$showProduct != 'ne' and $showProduct != 'ukončen'">N</xsl:if>
</HIDDEN>
</xsl:if>
<xsl:if test="cena-za-proklik-kc">
<MAX_CPC>
<xsl:value-of select="cena-za-proklik-kc"/>
</MAX_CPC>
</xsl:if>
<xsl:call-template name="getParameters"/>
<xsl:if test="string-length(merna-jednotka) > 0">
<MEASURE_UNIT>
<xsl:value-of select="merna-jednotka"/>
</MEASURE_UNIT>
</xsl:if>
<xsl:if test="number(jednotek-v-baleni) > 0">
<MEASURE_QUANTITY>
<xsl:value-of select="jednotek-v-baleni"/>
</MEASURE_QUANTITY>
</xsl:if>
<xsl:variable name="varCnt"
select="count(*[substring(name(),1, 8) = 'varianta' and not(normalize-space(text()) = '')])"/>
<xsl:if test="not($varCnt = 0)">
<VARIATIONS>
<xsl:call-template name="getVariations">
<xsl:with-param name="parentCode" select="$code"/>
<xsl:with-param name="rootElement" select="/xml/item"/>
</xsl:call-template>
</VARIATIONS>
</xsl:if>
<xsl:if test="$varCnt = 0">
<xsl:if test="string-length(ean) > 0">
<EAN>
<xsl:value-of select="ean"/>
</EAN>
</xsl:if>
<xsl:if test="not(string-length(ean)) and string-length(kod-ean) >= 8">
<EAN>
<xsl:value-of select="kod-ean"/>
</EAN>
</xsl:if>
<xsl:if test="skladem-ks">
<IN_STORE>
<xsl:value-of select="skladem-ks"/>
</IN_STORE>
</xsl:if>
<xsl:variable name="in_store_min" select="minimalne-skladem-ks"/>
<xsl:if test="$in_store_min">
<IN_STORE_MIN>
<xsl:value-of select="$in_store_min"/>
</IN_STORE_MIN>
</xsl:if>
<xsl:if test="dostupnost">
<AVAILABILITY>
<xsl:value-of select="dostupnost"/>
</AVAILABILITY>
</xsl:if>
<xsl:variable name="photos" select="*[substring(name(),1, 10) = 'fotografie' and not(normalize-space(text()) = '')]"/>
<xsl:if test="count($photos) > 0">
<PHOTOS>
<xsl:for-each select="$photos">
<PHOTO>
<xsl:value-of select="text()"/>
</PHOTO>
</xsl:for-each>
</PHOTOS>
</xsl:if>
</xsl:if>
</SHOPITEM>
</xsl:if>
</xsl:for-each>
</SHOP>
</xsl:template>
<!-- ___________________________________________________________________________________________________________ -->
<xsl:template name="getVat">
<xsl:if test="number(translate(sazba-dph,',','.')) > 0">
<VAT>
<xsl:value-of select="number(translate(sazba-dph,',','.'))"/>
</VAT>
</xsl:if>
<xsl:if test="not(number(translate(sazba-dph,',','.')) > 0)">
<xsl:if test="number(translate(cena-s-dph-kc,',','.')) > number(translate(cena-bez-dph-kc,',','.'))">
<VAT>
<xsl:value-of select="number(translate(cena-s-dph-kc,',','.')) div number(translate(cena-bez-dph-kc,',','.')) * 100"/>
</VAT>
</xsl:if>
</xsl:if>
<xsl:if test="oss-kategorie">
<VAT_CATEGORY>
<xsl:value-of select="oss-kategorie"/>
</VAT_CATEGORY>
</xsl:if>
</xsl:template>
<!-- ___________________________________________________________________________________________________________ -->
<xsl:template name="getPrice">
<xsl:if test="number(translate(cena-bez-dph-kc,',','.')) > 0">
<PRICE>
<xsl:value-of select="number(translate(cena-bez-dph-kc,',','.'))"/>
</PRICE>
</xsl:if>
<xsl:if test="not(number(translate(cena-bez-dph-kc,',','.')) > 0)">
<xsl:if test="number(translate(sazba-dph,',','.')) > 0 and number(translate(cena-s-dph-kc,',','.')) > 0">
<PRICE>
<xsl:value-of select="100 div (100 + number(translate(sazba-dph,',','.'))) * number(translate(cena-s-dph-kc,',','.'))"/>
</PRICE>
</xsl:if>
</xsl:if>
</xsl:template>
<!-- ___________________________________________________________________________________________________________ -->
<xsl:template name="getCommonPrice">
<xsl:if test="number(translate(bezna-cena-kc,',','.')) > 0">
<PRICE_COMMON>
<xsl:value-of select="number(translate(bezna-cena-kc,',','.'))"/>
</PRICE_COMMON>
</xsl:if>
<xsl:if test="number(translate(skrtla-cena-kc,',','.')) > 0">
<PRICE_COMMON>
<xsl:value-of select="number(translate(skrtla-cena-kc,',','.'))"/>
</PRICE_COMMON>
</xsl:if>
</xsl:template>
<!-- ___________________________________________________________________________________________________________ -->
<xsl:template name="getDiscount">
<xsl:if test="number(translate(sleva,',','.')) > 0">
<DISCOUNT>
<xsl:value-of select="number(translate(sleva,',','.'))"/>
</DISCOUNT>
</xsl:if>
<xsl:if test="not(number(translate(sleva,',','.')) > 0)">
<xsl:if test="number(translate(cena-po-sleve-bez-dph-kc,',','.')) > 0 and number(translate(cena-bez-dph-kc,',','.')) > 0">
<DISCOUNT>
<xsl:value-of
select="(1 - number(translate(cena-po-sleve-bez-dph-kc,',','.')) div number(translate(cena-bez-dph-kc,',','.'))) * 100"/>
</DISCOUNT>
</xsl:if>
<xsl:if test="not(number(translate(cena-po-sleve-bez-dph-kc,',','.')) > 0 and number(translate(cena-bez-dph-kc,',','.')) > 0)">
<xsl:if test="number(translate(cena-po-sleve-s-dph-kc,',','.')) > 0 and number(translate(cena-s-dph-kc,',','.')) > 0">
<DISCOUNT>
<xsl:value-of
select="(1 - number(translate(cena-po-sleve-s-dph-kc,',','.')) div number(translate(cena-s-dph-kc,',','.'))) * 100"/>
</DISCOUNT>
</xsl:if>
</xsl:if>
<xsl:if test="not(cena-po-sleve-bez-dph-kc) and not(cena-po-sleve-s-dph-kc) and number(translate(sleva,',','.')) = 0">
<DISCOUNT>0</DISCOUNT>
</xsl:if>
</xsl:if>
</xsl:template>
<!-- ___________________________________________________________________________________________________________ -->
<xsl:template name="getParameters">
<xsl:variable name="parameters" select="*[substring(name(),1, 8) = 'parametr' and not(normalize-space(text()) = '')]"/>
<xsl:if test="count($parameters) > 0">
<xsl:for-each select="$parameters">
<PARAMETER>
<xsl:variable name="tagName" select="name()"/>
<xsl:attribute name="name">
<xsl:value-of
select="normalize-space(substring(/xml/head/*[name() = $tagName][1], 10))"/>
</xsl:attribute>
<xsl:value-of select="text()"/>
</PARAMETER>
</xsl:for-each>
</xsl:if>
</xsl:template>
<!-- ___________________________________________________________________________________________________________ -->
<xsl:template name="getVariations">
<xsl:param name="parentCode"/>
<xsl:param name="rootElement"/>
<xsl:for-each select="$rootElement[kod=$parentCode]">
<VARIATION>
<CODE>
<xsl:if test="normalize-space(kod-ean) = ''">
<xsl:value-of select="concat(kod,'_',position(),'_U')"/>
</xsl:if>
<xsl:if test="not(normalize-space(kod-ean) = '')">
<xsl:value-of select="concat(kod,'_',kod-ean,'_U')"/>
</xsl:if>
</CODE>
<xsl:if test="string-length(ean) > 0">
<EAN>
<xsl:value-of select="ean"/>
</EAN>
</xsl:if>
<xsl:if test="not(string-length(ean)) and string-length(kod-ean) >= 8">
<EAN>
<xsl:value-of select="kod-ean"/>
</EAN>
</xsl:if>
<xsl:call-template name="getPrice"/>
<xsl:call-template name="getCommonPrice"/>
<xsl:call-template name="getPriceBuy"/>
<xsl:call-template name="getVat"/>
<xsl:call-template name="getDiscount"/>
<xsl:variable name="labels" select="*[substring(name(),1, 8) = 'varianta' and not(normalize-space(text()) = '')]"/>
<xsl:if test="count($labels) > 0">
<xsl:for-each select="$labels">
<LABEL>
<xsl:variable name="tagName" select="name()"/>
<xsl:attribute name="name">
<xsl:value-of select="normalize-space(substring(/xml/head/*[name() = $tagName][1], 10))"/>
</xsl:attribute>
<xsl:value-of select="text()"/>
</LABEL>
</xsl:for-each>
</xsl:if>
<xsl:if test="skladem-ks">
<IN_STORE>
<xsl:value-of select="skladem-ks"/>
</IN_STORE>
</xsl:if>
<xsl:variable name="in_store_min" select="minimalne-skladem-ks"/>
<xsl:if test="$in_store_min">
<IN_STORE_MIN>
<xsl:value-of select="$in_store_min"/>
</IN_STORE_MIN>
</xsl:if>
<xsl:if test="dostupnost">
<AVAILABILITY>
<xsl:value-of select="dostupnost"/>
</AVAILABILITY>
</xsl:if>
<xsl:variable name="photosVariations" select="*[substring(name(),1, 10) = 'fotografie' and not(normalize-space(text()) = '')]"/>
<xsl:if test="count($photosVariations) > 0">
<PHOTOS>
<xsl:for-each select="$photosVariations">
<PHOTO>
<xsl:value-of select="text()"/>
</PHOTO>
</xsl:for-each>
</PHOTOS>
</xsl:if>
<xsl:if test="number(jednotek-v-baleni) > 0">
<MEASURE_QUANTITY>
<xsl:value-of select="jednotek-v-baleni"/>
</MEASURE_QUANTITY>
</xsl:if>
</VARIATION>
</xsl:for-each>
</xsl:template>
<!-- ___________________________________________________________________________________________________________ -->
<xsl:template name="getPriceBuy">
<xsl:for-each select="*[substring(name(),1, 23) = 'cena-dodavatele-bez-dph' and not(normalize-space(text()) = '')]">
<xsl:if test="text()">
<PRICE_BUY>
<xsl:value-of select="text()"/>
</PRICE_BUY>
</xsl:if>
</xsl:for-each>
<xsl:for-each
select="*[substring(name(),1, 20) = 'nakupni-cena-bez-dph' and not(normalize-space(text()) = '')]">
<xsl:if test="text()">
<PRICE_BUY>
<xsl:value-of select="text()"/>
</PRICE_BUY>
</xsl:if>
</xsl:for-each>
</xsl:template>
<!-- ___________________________________________________________________________________________________________ -->
<xsl:template name="getPriceList">
<xsl:variable name="priceLists" select="*[substring(name(),1, 13) = 'cenik-bez-dph' and not(normalize-space(text()) = '')]"/>
<xsl:variable name="priceLists2" select="*[substring(name(),1, 11) = 'cenik-sleva' and not(normalize-space(text()) = '')]"/>
<xsl:if test="count($priceLists) > 0 or count($priceLists2) > 0">
<PRICELISTS>
<xsl:for-each select="$priceLists">
<PRICELIST>
<xsl:variable name="tagName" select="name()"/>
<xsl:attribute name="name">
<xsl:value-of
select="normalize-space(substring(/xml/head/*[name() = $tagName][1], 15))"/>
</xsl:attribute>
<PRICE>
<xsl:value-of select="text()"/>
</PRICE>
</PRICELIST>
</xsl:for-each>
<xsl:for-each select="$priceLists2">
<PRICELIST>
<xsl:variable name="tagName" select="name()"/>
<xsl:attribute name="name">
<xsl:value-of
select="normalize-space(substring(/xml/head/*[name() = $tagName][1], 13))"/>
</xsl:attribute>
<DISCOUNT>
<xsl:value-of select="text()"/>
</DISCOUNT>
</PRICELIST>
</xsl:for-each>
</PRICELISTS>
</xsl:if>
</xsl:template>
<!-- ___________________________________________________________________________________________________________ -->
<xsl:template name="getLinks">
<xsl:variable name="links" select="*[substring(name(),1, 5) = 'odkaz' and not(normalize-space(text()) = '')]"/>
<xsl:if test="count($links) > 0">
<LINKS>
<xsl:for-each select="$links">
<xsl:if test="string-length(name()) > 0">
<LINK>
<xsl:variable name="tagName" select="name()"/>
<xsl:variable name="linkType">
<xsl:value-of select="translate(normalize-space(substring(/xml/head/*[name() = $tagName][1], 7)), '[]', '')"/>
</xsl:variable>
<xsl:attribute name="type">
<xsl:value-of select="$linkType"/>
</xsl:attribute>
<xsl:value-of select="text()"/>
</LINK>
</xsl:if>
</xsl:for-each>
</LINKS>
</xsl:if>
</xsl:template>
</xsl:stylesheet>