簡體   English   中英

XSLT 1.0,使用身份轉換,多個模板無法匹配

[英]XSLT 1.0, Using Identity Transform, with multiple templates fails to match

哇,自從大約 15 年前編程介紹以來,我沒有問過這么多問題,這個 XSLT 的東西讓我很興奮,我一直在學習使用 Identity Transform。 取一個字符串並根據分隔符將其分解為節點,我按預期工作。 但是當我將它與我的邏輯的 rest 結合使用時,它會中斷。 我認為這與我對元素本身的選擇器有關。 我為自己找到了一個身份轉換的基本示例而感到自豪,我一直在工作和學習。 從這里開始。 XSLT 1.0 - Output Count of Value Uniqueness in a Node with Vanilla XSLT 1.0 or PHP XSLT I think selectors and order of operations are going to be the next things I need to wrap my head around.

任何幫助將不勝感激。 :)

源數據已編輯不要使用,因為我最初提供了有缺陷的數據,並在下面添加了更新的數據。

<root>
  <part>
    <partNumber>33020780</partNumber>
    <punctuatedPartNumber>3302-0780</punctuatedPartNumber>
    <partStatusDescription>STANDARD</partStatusDescription>
    <partDescription>Women's Hooligan Glove - Black - 2XL</partDescription>
    <unitOfMeasure>Pair</unitOfMeasure>
    <brandName>ICON</brandName>
    <supplierNumber></supplierNumber>
    <specialInstructions/>
    <baseDealerPrice>15.0000</baseDealerPrice>
    <yourDealerPrice>15.0000</yourDealerPrice>
    <baseRetailPrice>30.0000</baseRetailPrice>
    <originalRetailPrice>30.0000</originalRetailPrice>
    <partImage>http://asset.lemansnet.com/z/L0UvOS8zL0U5M0JDMzM4LUNEMDAtNDhGNi1CMjQzLTJCM0U3ODBCQzU0NCwvRC85LzEvRDkxQUQ1ODQtQjU0Ny00MTYzLUIxNDgtMzk3MTMwOEU2N0U5</partImage>
    <productId>1967508881</productId>
    <productName>Women's Hooligan™ Gloves</productName>
    <productImage>http://asset.lemansnet.com/z/bWVkaWEvYzY1Y2JiYzctYTk4OC00OTY0LWJlYTEtNzYzZDFiYmQ4NzBlLC9FLzkvMy9FOTNCQzMzOC1DRDAwLTQ4RjYtQjI0My0yQjNFNzgwQkM1NDQsejJodWhwWVN1cGc=</productImage>
    <bullet1>Durable nylon/synthetic suede construction</bullet1>
    <bullet2>AxSuede Laredo palm</bullet2>
    <bullet3>Thermoplastic knuckle armor for durable, flexible protection</bullet3>
    <bullet4>Ram air finger inserts help keep hands cool</bullet4>
    <bullet5>Snap secures gloves together when not in use</bullet5>
    <bullet6/>
    <bullet7/>
    <bullet8/>
    <bullet9/>
    <bullet10/>
    <bullet11/>
    <bullet12/>
    <bullet13/>
    <bullet14/>
    <bullet15/>
    <bullet16/>
    <bullet17/>
    <bullet18/>
    <bullet19/>
    <bullet20/>
    <bullet21/>
    <bullet22/>
    <bullet23/>
    <bullet24/>
  </part>
  <part>
    <partNumber>33020783</partNumber>
    <punctuatedPartNumber>3302-0783</punctuatedPartNumber>
    <partStatusDescription>STANDARD</partStatusDescription>
    <partDescription>Women's Hooligan Glove - Pink - Medium</partDescription>
    <unitOfMeasure>Pair</unitOfMeasure>
    <brandName>ICON</brandName>
    <supplierNumber></supplierNumber>
    <specialInstructions/>
    <baseDealerPrice>15.0000</baseDealerPrice>
    <yourDealerPrice>15.0000</yourDealerPrice>
    <baseRetailPrice>30.0000</baseRetailPrice>
    <originalRetailPrice>30.0000</originalRetailPrice>
    <partImage>http://asset.lemansnet.com/z/L0UvRi8zL0VGMzE4NzU3LTZCNDAtNDUyNi1CMjY3LTRBMzYzNTI2RkU1RSwvMC9EL0MvMERDQ0NCQTktMEVEOC00QzI0LThBRDYtOTRDNzVCQUU5NUVC</partImage>
    <productId>1967508881</productId>
    <productName>Women's Hooligan™ Gloves</productName>
    <productImage>http://asset.lemansnet.com/z/bWVkaWEvYzY1Y2JiYzctYTk4OC00OTY0LWJlYTEtNzYzZDFiYmQ4NzBlLC9FLzkvMy9FOTNCQzMzOC1DRDAwLTQ4RjYtQjI0My0yQjNFNzgwQkM1NDQsejJodWhwWVN1cGc=</productImage>
    <bullet1>Durable nylon/synthetic suede construction</bullet1>
    <bullet2>AxSuede Laredo palm</bullet2>
    <bullet3>Thermoplastic knuckle armor for durable, flexible protection</bullet3>
    <bullet4>Ram air finger inserts help keep hands cool</bullet4>
    <bullet5>Snap secures gloves together when not in use</bullet5>
    <bullet6/>
    <bullet7/>
    <bullet8/>
    <bullet9/>
    <bullet10/>
    <bullet11/>
    <bullet12/>
    <bullet13/>
    <bullet14/>
    <bullet15/>
    <bullet16/>
    <bullet17/>
    <bullet18/>
    <bullet19/>
    <bullet20/>
    <bullet21/>
    <bullet22/>
    <bullet23/>
    <bullet24/>
  </part>
</root>

工作身份轉換

<xsl:stylesheet version="1.0" 
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

    <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
    <xsl:strip-space elements="*"/>

    <xsl:template match="@*|node()">
        <xsl:copy>
            <xsl:apply-templates select="@*|node()"/>
        </xsl:copy>
    </xsl:template>

    <xsl:template match="partDescription" name="tokenize">
        <xsl:param name="text" select="."/>
        <xsl:param name="delimiter" select="' - '"/>
        <xsl:param name="keys" select="'short_name,color,size'"/>
        <xsl:element name="{substring-before($keys, ',')}">
            <xsl:value-of select="substring-before(concat($text, $delimiter), $delimiter)" />
        </xsl:element>
        <xsl:if test="contains($text, $delimiter)">
            <xsl:call-template name="tokenize">
                <xsl:with-param name="text" select="substring-after($text, $delimiter)"/>
                <xsl:with-param name="keys" select="substring-after($keys, ',')"/>
            </xsl:call-template>
        </xsl:if>
    </xsl:template>

</xsl:stylesheet>

破碎的完整示例,當我說破碎的結果只是<items/>

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
    
    <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
    <xsl:key name="part-by-product" match="part" use="productId" />
    <xsl:strip-space elements="*"/>

    <!-- Transform Data  -->
    <xsl:template match="@*|node()">
        <xsl:copy>
            <xsl:apply-templates select="@*|node()"/>
        </xsl:copy>
    </xsl:template>

    <!-- Parse Description as Keys  -->
    <xsl:template match="partDescription" name="tokenize">
        <xsl:param name="text" select="."/>
        <xsl:param name="delimiter" select="' - '"/>
        <xsl:param name="keys" select="'short_name,color,size'"/>
        <xsl:element name="{substring-before($keys, ',')}">
            <xsl:value-of select="substring-before(concat($text, $delimiter), $delimiter)" />
        </xsl:element>
        <xsl:if test="contains($text, $delimiter)">
            <xsl:call-template name="tokenize">
                <xsl:with-param name="text" select="substring-after($text, $delimiter)"/>
                <xsl:with-param name="keys" select="substring-after($keys, ',')"/>
            </xsl:call-template>
        </xsl:if>
    </xsl:template>

    <xsl:template match="/root">
        <xsl:element name="items">
            <xsl:for-each select="part[supplierNumber/text() and partStatusDescription != 'DISCONTINUED']">
                <xsl:element name="item">
                    
                    <!-- finish -->
                    <xsl:choose>
                        <xsl:when test="contains(partDescription, 'Black')">
                            <finish>Black</finish>
                        </xsl:when>
                        <xsl:when test="contains(partDescription, 'Flat Back')">
                            <finish>Flat Back</finish>
                        </xsl:when>
                        <xsl:when test="contains(partDescription, 'Chrome')">
                            <finish>Chrome</finish>
                        </xsl:when>
                    </xsl:choose>
                    
                    <!-- size -->
                    <xsl:call-template name="find-size">
                        <xsl:with-param name="text" select="partDescription"/>
                    </xsl:call-template>

                    <!-- Check if a Product should be configurable -->
                    <xsl:copy-of select="partNumber | productId"/>
                    <!-- check productId uniqueness -->
                    <xsl:if test="count(key('part-by-product', productId)) > 1">
                        <configurableId>
                            <xsl:value-of select="productId"/>
                        </configurableId>
                    </xsl:if>

                    <xsl:element name="name">
                         <xsl:value-of select="concat(brandName,' ',productName)"/>
                    </xsl:element>
                    <punctuatedPartNumber>
                        <xsl:value-of select="punctuatedPartNumber"/>
                    </punctuatedPartNumber>
                     <xsl:element name="is_in_stock">
                        <xsl:if test="partStatusDescription = 'STANDARD'">
                                <xsl:value-of select="1"/>
                        </xsl:if>
                        <xsl:if test="partStatusDescription != 'STANDARD'">
                            <xsl:value-of select="0"/>
                        </xsl:if>    
                    </xsl:element>
                    <partDescription>
                        <xsl:value-of select="partDescription"/>
                    </partDescription>
                    <unitOfMeasure>
                        <xsl:value-of select="unitOfMeasure"/>
                    </unitOfMeasure>
                    <brandName>
                        <xsl:value-of select="brandName"/>
                    </brandName>
                    <supplierNumber>
                        <xsl:value-of select="supplierNumber"/>
                    </supplierNumber>
                    <specialInstructions>
                        <xsl:value-of select="specialInstructions"/>
                    </specialInstructions>
                    <xsl:element name="price">
                        <xsl:value-of select="(originalRetailPrice * 100) div 100"/>
                    </xsl:element>
                    <xsl:element name="special_price">
                        <xsl:if test="baseRetailPrice  &lt; originalRetailPrice">
                            <xsl:value-of select="baseRetailPrice"/>
                        </xsl:if>
                    </xsl:element>
                    <partImage>
                        <xsl:value-of select="partImage"/>
                    </partImage>
                    <productName>
                        <xsl:value-of select="productName"/>
                    </productName>
                    <productImage>
                        <xsl:value-of select="productImage"/>
                    </productImage>
                    <bullet1>
                        <xsl:value-of select="bullet1"/>
                    </bullet1>
                    <bullet2>
                        <xsl:value-of select="bullet2"/>
                    </bullet2>
                    <bullet3>
                        <xsl:value-of select="bullet3"/>
                    </bullet3>
                    <bullet4>
                        <xsl:value-of select="bullet4"/>
                    </bullet4>

                </xsl:element>
            </xsl:for-each>
        </xsl:element>
    </xsl:template>

    <xsl:template name="find-size">
        <xsl:param name="text"/>
        <xsl:param name="delimiter" select="' '"/>
        <xsl:variable name="token" select="substring-before(concat($text, $delimiter), $delimiter)" />
        <xsl:choose>
            <xsl:when test="starts-with(translate($token, '123456789', '000000000'), '0')">
                <size>
                    <xsl:value-of select="$token"/>
                </size>
            </xsl:when>
            <xsl:when test="contains($text, $delimiter)">
                <!-- recursive call -->
                <xsl:call-template name="find-size">
                    <xsl:with-param name="text" select="substring-after($text, $delimiter)"/>
                </xsl:call-template>
            </xsl:when>
        </xsl:choose>
    </xsl:template>

</xsl:stylesheet>

***************************** 以下已編輯 ******************* ***********

更新數據樣本

我提供了樣本數據,這些數據永遠不會發生意外,這也解釋了為什么我只收到了原始節點元素。 但是,即使修復了我的愚蠢錯誤,我的代碼組合也不起作用

<root>
  <part>
    <partNumber>33020576</partNumber>
    <punctuatedPartNumber>3302-0576</punctuatedPartNumber>
    <partStatusDescription>STANDARD</partStatusDescription>
    <partDescription>Stella SP-8 V2 Gloves - Black/White/Pink - Large</partDescription>
    <unitOfMeasure>Pair</unitOfMeasure>
    <brandName>ALPINESTARS (ROAD)</brandName>
    <supplierNumber>3518317-1239-L</supplierNumber>
    <specialInstructions/>
    <baseDealerPrice>68.0000</baseDealerPrice>
    <yourDealerPrice>68.0000</yourDealerPrice>
    <baseRetailPrice>99.9500</baseRetailPrice>
    <originalRetailPrice>99.9500</originalRetailPrice>
    <partImage>http://asset.lemansnet.com/z/L0EvRC84L0FEODhFNTI1LTBGRjItNEY3NC1CRTBDLTg4RkNBNjdCREVFQw==</partImage>
    <productId>0975297251</productId>
    <productName>Stella SP-8 V2 Leather Gloves</productName>
    <productImage>http://asset.lemansnet.com/z/LzcvMC9CLzcwQkJGNjJGLURDMDUtNDY0RC1BQ0YzLTQxN0FEQ0E3RDgwNCxtZWRpYS82OGFiOGQ5YS0wMDhiLTQ1NDctOGExMC1jZTBhNGU2MmUyNzQsbWVkaWEvYzZlODQwNDEtZTViMy00YTExLWJjYjUtODJiMDQ5NmI4OGZl</productImage>
    <bullet1>Tall, relaxed sport glove</bullet1>
    <bullet2>Premium, full-grain leather construction is durable and offers excellent abrasion resistance.</bullet2>
    <bullet3>An innovative microfiber and Polyurethane coated (PU) grip insert strategically position on palm and thumb for excellent levels of grip control and durability.</bullet3>
    <bullet4>Chassis is profiled for female specific fit and Alpinestars’ exclusive ergonomic stretch insert between palm and thumb offers improved range of hand movement and greater sensitivity while operating the bike controls.</bullet4>
    <bullet5>Incorporates premium quality suede palm and landing reinforcement for grip, control and durability.</bullet5>
    <bullet6>Alpinestars’ patented third and fourth finger bridge prevents seam failure and finger separation in the event of a slide.</bullet6>
    <bullet7>Excellent repeated impact performance offered by an advanced over-molded polymer knuckle protector.</bullet7>
    <bullet8>Ethylene vinyl acetate (EVA) foam padding reinforcements on thumb, wrist, back of hand, finger and palm for comfort and abrasion performance.</bullet8>
    <bullet9>Perforated leather cuff, plus perforated finger sidewalls for superb breathability.</bullet9>
    <bullet10>Velcro cuff closure, plus elasticized wrist design for secure, personalized fit.</bullet10>
    <bullet11>Pre-shaped fingers and external seams for comfort and exceptional feel.</bullet11>
    <bullet12>Printed and embroidered logos on wrist and fingers, plus heat stamped logo on knuckle.</bullet12>
    <bullet13>Touchscreen compatible fingertip on index finger for use with touch screen devices.</bullet13>
    <bullet14/>
    <bullet15/>
    <bullet16/>
    <bullet17/>
    <bullet18/>
    <bullet19/>
    <bullet20/>
    <bullet21/>
    <bullet22/>
    <bullet23/>
    <bullet24/>
  </part>
  <part>
    <partNumber>33020577</partNumber>
    <punctuatedPartNumber>3302-0577</punctuatedPartNumber>
    <partStatusDescription>STANDARD</partStatusDescription>
    <partDescription>Stella SP-8 V2 Gloves - Black/White/Pink - XL</partDescription>
    <unitOfMeasure>Pair</unitOfMeasure>
    <brandName>ALPINESTARS (ROAD)</brandName>
    <supplierNumber>3518317-1239-XL</supplierNumber>
    <specialInstructions/>
    <baseDealerPrice>68.0000</baseDealerPrice>
    <yourDealerPrice>68.0000</yourDealerPrice>
    <baseRetailPrice>99.9500</baseRetailPrice>
    <originalRetailPrice>99.9500</originalRetailPrice>
    <partImage>http://asset.lemansnet.com/z/L0EvRC84L0FEODhFNTI1LTBGRjItNEY3NC1CRTBDLTg4RkNBNjdCREVFQw==</partImage>
    <productId>0975297251</productId>
    <productName>Stella SP-8 V2 Leather Gloves</productName>
    <productImage>http://asset.lemansnet.com/z/LzcvMC9CLzcwQkJGNjJGLURDMDUtNDY0RC1BQ0YzLTQxN0FEQ0E3RDgwNCxtZWRpYS82OGFiOGQ5YS0wMDhiLTQ1NDctOGExMC1jZTBhNGU2MmUyNzQsbWVkaWEvYzZlODQwNDEtZTViMy00YTExLWJjYjUtODJiMDQ5NmI4OGZl</productImage>
    <bullet1>Tall, relaxed sport glove</bullet1>
    <bullet2>Premium, full-grain leather construction is durable and offers excellent abrasion resistance.</bullet2>
    <bullet3>An innovative microfiber and Polyurethane coated (PU) grip insert strategically position on palm and thumb for excellent levels of grip control and durability.</bullet3>
    <bullet4>Chassis is profiled for female specific fit and Alpinestars’ exclusive ergonomic stretch insert between palm and thumb offers improved range of hand movement and greater sensitivity while operating the bike controls.</bullet4>
    <bullet5>Incorporates premium quality suede palm and landing reinforcement for grip, control and durability.</bullet5>
    <bullet6>Alpinestars’ patented third and fourth finger bridge prevents seam failure and finger separation in the event of a slide.</bullet6>
    <bullet7>Excellent repeated impact performance offered by an advanced over-molded polymer knuckle protector.</bullet7>
    <bullet8>Ethylene vinyl acetate (EVA) foam padding reinforcements on thumb, wrist, back of hand, finger and palm for comfort and abrasion performance.</bullet8>
    <bullet9>Perforated leather cuff, plus perforated finger sidewalls for superb breathability.</bullet9>
    <bullet10>Velcro cuff closure, plus elasticized wrist design for secure, personalized fit.</bullet10>
    <bullet11>Pre-shaped fingers and external seams for comfort and exceptional feel.</bullet11>
    <bullet12>Printed and embroidered logos on wrist and fingers, plus heat stamped logo on knuckle.</bullet12>
    <bullet13>Touchscreen compatible fingertip on index finger for use with touch screen devices.</bullet13>
    <bullet14/>
    <bullet15/>
    <bullet16/>
    <bullet17/>
    <bullet18/>
    <bullet19/>
    <bullet20/>
    <bullet21/>
    <bullet22/>
    <bullet23/>
    <bullet24/>
  </part>
</root>

好吧,在過濾我的數據並使用本來會被過濾掉的樣本數據之后犯了一個重大錯誤。 然后,通過我原來使用的以下內容,學習,一個關鍵的部分,你在使用“模板匹配”時必須小心和深思熟慮

<xsl:template match="@*|node()">
    <xsl:copy>
        <xsl:apply-templates select="@*|node()"/>
    </xsl:copy>
</xsl:template>

所以,我最終要做的是轉換,從嘗試匹配模板級別的所有內容,而是創建一個基本的 function,它將節點作為參數並返回標記化結果。 雖然,我絕對知道有更有效的方法來實現我的目標,我的 XSLT 代碼看起來像是一個孩子寫的,希望有人能從我的努力中學習。

簡化版本,便於閱讀。

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
    
    <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
    <xsl:key name="part-by-product" match="part" use="productId" />
    <xsl:strip-space elements="*"/>

    <xsl:template match="/root">
        <xsl:element name="items">
            <xsl:for-each select="part[supplierNumber/text() and partStatusDescription != 'DISCONTINUED']">
                <xsl:element name="item">
                    
                    <!-- Call the custom template, and pass the node partDescription to the template -->
                    <xsl:call-template name="tokenize">
                        <xsl:with-param name="text" select="partDescription"/>
                    </xsl:call-template>

                </xsl:element>
            </xsl:for-each>
        </xsl:element>
    </xsl:template>

    <!-- A template that accepts a node with text passesd as a select  -->
    <xsl:template name="tokenize">
        <xsl:param name="text"/>
        <xsl:param name="delimiter" select="' - '"/>
        <xsl:param name="keys" select="'name,color,size,configurable1,configurable2'"/>
        <xsl:element name="{substring-before($keys, ',')}">
            <xsl:value-of select="substring-before(concat($text, $delimiter), $delimiter)" />
        </xsl:element>
        <xsl:if test="contains($text, $delimiter)">
            <xsl:call-template name="tokenize">
                <xsl:with-param name="text" select="substring-after($text, $delimiter)"/>
                <xsl:with-param name="keys" select="substring-after($keys, ',')"/>
            </xsl:call-template>
        </xsl:if>
    </xsl:template>

</xsl:stylesheet>

我的預期結果基於完成的示例,我將在此之后分享

<items>
    <item>
        <!-- This was the main goal this task, and what the above sample completes  -->
        <name>SP-8 V2 Gloves</name>
        <color>Black/White/Yellow</color>
        <size>3XL</size>
        <!-- The rest of the result that can be viewed by running the complete XSTL template -->
        <finish>Black</finish>
        <size>3XL</size>
        <partNumber>33012993</partNumber>
        <productId>0067377912</productId>
        <name>ALPINESTARS (ROAD) SP-8 V2 Gloves</name>
        <punctuatedPartNumber>3301-2993</punctuatedPartNumber>
        <is_in_stock>1</is_in_stock>
        <partDescription>SP-8 V2 Gloves - Black/White/Yellow - 3XL</partDescription>
        <unitOfMeasure>Pair</unitOfMeasure>
        <brandName>ALPINESTARS (ROAD)</brandName>
        <supplierNumber>3558317-125-3X</supplierNumber>
        <specialInstructions/>
        <price>99.95</price>
        <special_price/>
        <partImage>http://asset.lemansnet.com/z/LzkvNy9FLzk3RUYyQTg3LTM4QTItNDZEQy1CNzE2LThGMjNEQjQxNzgzOA==</partImage>
        <productName>SP-8 V2 Gloves</productName>
        <productImage>http://asset.lemansnet.com/z/L0UvRS9FL0VFRUEwQzRCLUZCRDktNDUzQS1CMTg3LUVCMTY2OUM5N0ZDQywvRi8yL0MvRjJDQjRERTMtQUM2MC00M0ZCLUFERDktMzE0NTA4QTIxQjcyLC8zLzAvNy8zMDdGRTEzMy0zMUFFLTQzQ0ItOTM3MC00NzY1OEI3RUM4MUEsbWVkaWEvNjhhYjhkOWEtMDA4Yi00NTQ3LThhMTAtY2UwYTRlNjJlMjc0LG1lZGlhL2M2ZTg0MDQxLWU1YjMtNGExMS1iY2I1LTgyYjA0OTZiODhmZQ==</productImage>
        <bullet1>Premium, full-grain leather construction is durable and offers excellent abrasion resistance</bullet1>
        <bullet2>An innovative microfiber and Polyurethane (PU) grip insert strategically position on palm and thumb</bullet2>
        <bullet3>Alpinestars’ exclusive ergonomic stretch insert between palm and thumb</bullet3>
        <bullet4>Premium quality suede palm and landing reinforcement.</bullet4>
    </item>
</items>

基於我的原始示例的完整版本

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
    
    <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
    <xsl:key name="part-by-product" match="part" use="productId" />
    <xsl:strip-space elements="*"/>

    <xsl:template match="/root">
        <xsl:element name="items">
            <xsl:for-each select="part[supplierNumber/text() and partStatusDescription != 'DISCONTINUED']">
                <xsl:element name="item">
                    
                    <xsl:call-template name="tokenize">
                        <xsl:with-param name="text" select="partDescription"/>
                    </xsl:call-template>

                    <!-- finish -->
                    <xsl:choose>
                        <xsl:when test="contains(partDescription, 'Black')">
                            <finish>Black</finish>
                        </xsl:when>
                        <xsl:when test="contains(partDescription, 'Flat Back')">
                            <finish>Flat Back</finish>
                        </xsl:when>
                        <xsl:when test="contains(partDescription, 'Chrome')">
                            <finish>Chrome</finish>
                        </xsl:when>
                    </xsl:choose>
                    
                    <!-- size -->
                    <xsl:call-template name="find-size">
                        <xsl:with-param name="text" select="partDescription"/>
                    </xsl:call-template>

                    <!-- Check if a Product should be configurable -->
                    <xsl:copy-of select="partNumber | productId"/>
                    <!-- check productId uniqueness -->
                    <xsl:if test="count(key('part-by-product', productId)) > 1">
                        <configurableId>
                            <xsl:value-of select="productId"/>
                        </configurableId>
                    </xsl:if>

                    <xsl:element name="name">
                         <xsl:value-of select="concat(brandName,' ',productName)"/>
                    </xsl:element>
                    <punctuatedPartNumber>
                        <xsl:value-of select="punctuatedPartNumber"/>
                    </punctuatedPartNumber>
                     <xsl:element name="is_in_stock">
                        <xsl:if test="partStatusDescription = 'STANDARD'">
                                <xsl:value-of select="1"/>
                        </xsl:if>
                        <xsl:if test="partStatusDescription != 'STANDARD'">
                            <xsl:value-of select="0"/>
                        </xsl:if>    
                    </xsl:element>
                    <partDescription>
                        <xsl:value-of select="partDescription"/>
                    </partDescription>
                    <unitOfMeasure>
                        <xsl:value-of select="unitOfMeasure"/>
                    </unitOfMeasure>
                    <brandName>
                        <xsl:value-of select="brandName"/>
                    </brandName>
                    <supplierNumber>
                        <xsl:value-of select="supplierNumber"/>
                    </supplierNumber>
                    <specialInstructions>
                        <xsl:value-of select="specialInstructions"/>
                    </specialInstructions>
                    <xsl:element name="price">
                        <xsl:value-of select="(originalRetailPrice * 100) div 100"/>
                    </xsl:element>
                    <xsl:element name="special_price">
                        <xsl:if test="baseRetailPrice  &lt; originalRetailPrice">
                            <xsl:value-of select="baseRetailPrice"/>
                        </xsl:if>
                    </xsl:element>
                    <partImage>
                        <xsl:value-of select="partImage"/>
                    </partImage>
                    <productName>
                        <xsl:value-of select="productName"/>
                    </productName>
                    <productImage>
                        <xsl:value-of select="productImage"/>
                    </productImage>
                    <bullet1>
                        <xsl:value-of select="bullet1"/>
                    </bullet1>
                    <bullet2>
                        <xsl:value-of select="bullet2"/>
                    </bullet2>
                    <bullet3>
                        <xsl:value-of select="bullet3"/>
                    </bullet3>
                    <bullet4>
                        <xsl:value-of select="bullet4"/>
                    </bullet4>

                </xsl:element>
            </xsl:for-each>
        </xsl:element>
    </xsl:template>

    <!-- Parse Description as Keys  -->
    <xsl:template name="tokenize">
        <xsl:param name="text"/>
        <xsl:param name="delimiter" select="' - '"/>
        <xsl:param name="keys" select="'name,color,size,configurable1,configurable2'"/>
        <xsl:element name="{substring-before($keys, ',')}">
            <xsl:value-of select="substring-before(concat($text, $delimiter), $delimiter)" />
        </xsl:element>
        <xsl:if test="contains($text, $delimiter)">
            <xsl:call-template name="tokenize">
                <xsl:with-param name="text" select="substring-after($text, $delimiter)"/>
                <xsl:with-param name="keys" select="substring-after($keys, ',')"/>
            </xsl:call-template>
        </xsl:if>
    </xsl:template>

    <!-- Size Template Engine -->
    <xsl:template name="find-size">
        <xsl:param name="text"/>
        <xsl:param name="delimiter" select="' '"/>
        <xsl:variable name="token" select="substring-before(concat($text, $delimiter), $delimiter)" />
        <xsl:choose>
            <xsl:when test="starts-with(translate($token, '123456789', '000000000'), '0')">
                <size>
                    <xsl:value-of select="$token"/>
                </size>
            </xsl:when>
            <xsl:when test="contains($text, $delimiter)">
                <!-- recursive call -->
                <xsl:call-template name="find-size">
                    <xsl:with-param name="text" select="substring-after($text, $delimiter)"/>
                </xsl:call-template>
            </xsl:when>
        </xsl:choose>
    </xsl:template>

</xsl:stylesheet>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM