Muenchian 分组 - 按未出现在 xml 结果中进行分组
Muenchian Grouping - Group by not appearing in xml result
我有以下 CSV 文件,XSD 看起来像这样:
123456|123456777|Green|Grün
123456|123456888|Red|Rot
987654|987654333|Yellow|Gelb
In XML format it looks like this:
<Product xmlns="http://F.FlatFileSchema1">
<Products xmlns="">
<product>123456</product>
<sku>123456777</sku>
<parentcolour_EN>Green</parentcolour_EN>
<parentcolour_DE>Grün</parentcolour_DE>
</Products>
<Products xmlns="">
<product>123456</product>
<sku>123456888</sku>
<parentcolour_EN>Red</parentcolour_EN>
<parentcolour_DE>Rot</parentcolour_DE>
</Products>
<Products xmlns="">
<product>987654</product>
<sku>987654333</sku>
<parentcolour_EN>Yellow</parentcolour_EN>
<parentcolour_DE>Gelb</parentcolour_DE>
</Products>
</Product>
目的是将其转换为具有以下格式的 xml:
<?xml version="1.0" encoding="utf-8"?>
<enfinity xsi:schemaLocation="http://www.intershop.com/xml/ns/enfinity/7.0/xcs/impex catalog.xsd http://www.intershop.com/xml/ns/enfinity/6.5/core/impex-dt dt.xsd" major="6" minor="1" family="enfinity" branch="enterprise" build="build" xmlns="http://www.intershop.com/xml/ns/enfinity/7.0/xcs/impex" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:dt="http://www.intershop.com/xml/ns/enfinity/6.5/core/impex-dt">
<offer sku="123456777">
<custom-attributes>
<custom-attribute name="parentcolour" dt:dt="string" xml:lang="en-US">Green</custom-attribute>
<custom-attribute name="parentcolour" dt:dt="string" xml:lang="de-DE">Grün</custom-attribute>
</custom-attributes>
</offer>
<offer sku="123456888">
<custom-attributes>
<custom-attribute name="parentcolour" dt:dt="string" xml:lang="en-US">Red</custom-attribute>
<custom-attribute name="parentcolour" dt:dt="string" xml:lang="de-DE">Rot</custom-attribute>
</custom-attributes>
</offer>
<offer sku="123456">
<variations>
<mastered-products>
<mastered-product sku="123456777" domain="MasterRepository"/>
<mastered-product sku="123456888" domain="MasterRepository"/>
</mastered-products>
</variations>
</offer>
<offer sku="987654333">
<custom-attributes>
<custom-attribute name="parentcolour" dt:dt="string" xml:lang="en-US">Yellow</custom-attribute>
<custom-attribute name="parentcolour" dt:dt="string" xml:lang="de-DE">Gelb</custom-attribute>
</custom-attributes>
</offer>
<offer sku="987654">
<variations>
<mastered-products>
<mastered-product sku="987654333" domain="MasterRepository"/>
</mastered-products>
</variations>
</offer>
</enfinity>
如您所见,XML中确实出现了所有 3 个 SKU,但还需要在 SKU 的末尾出现一个额外的产品,即 123456 出现在 123456777 和 123456888 之后,987654 出现在 987654333 之后. 到目前为止,我无法在应用 Muenchian 分组后显示产品级别的变化块。我当前的 XSL 如下所示:
<?xml version="1.0" encoding="UTF-16"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:s0="http://F.FlatFileSchema1" xmlns:xml="http://www.w3.org/XML/1998/namespace" exclude-result-prefixes="s0">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:key name="groupbyproduct" match="offer" use="product"/>
<xsl:template match="/s0:Product">
<enfinity xsi:schemaLocation="http://www.intershop.com/xml/ns/enfinity/7.0/xcs/impex catalog.xsd http://www.intershop.com/xml/ns/enfinity/6.5/core/impex-dt dt.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.intershop.com/xml/ns/enfinity/7.0/xcs/impex" xmlns:xml="http://www.w3.org/XML/1998/namespace" xmlns:dt="http://www.intershop.com/xml/ns/enfinity/6.5/core/impex-dt" major="6" minor="1" family="enfinity" branch="enterprise" build="build">
<xsl:for-each select="Products">
<offer sku="{sku}">
<custom-attributes>
<custom-attribute name="parentcolour" dt:dt="string" xml:lang="en-US">
<xsl:value-of select="parentcolour_EN/text()"/>
</custom-attribute>
<custom-attribute name="parentcolour" dt:dt="string" xml:lang="de-DE">
<xsl:value-of select="parentcolour_DE/text()"/>
</custom-attribute>
</custom-attributes>
</offer>
</xsl:for-each>
<!-- create a group for each unique product -->
<xsl:for-each select="offer[count(. | key('groupbyproduct', product)[1]) = 1]">
<offer sku="{product}">
<variations>
<mastered-products>
<!-- for each member of current group -->
<xsl:for-each select="key('groupbyproduct', product)">
<mastered-product sku="{sku}" domain="MasterRepository"/>
</xsl:for-each>
</mastered-products>
</variations>
</offer>
</xsl:for-each>
</enfinity>
</xsl:template>
</xsl:stylesheet>
密钥没有意义,我想你想要 <xsl:key name="groupbyproduct" match="Products" use="product"/>
然后你想要
而不是第二个 for-each
<!-- create a group for each unique product -->
<xsl:for-each select="Products[count(. | key('groupbyproduct', product)[1]) = 1]">
<offer sku="{product}">
<variations>
<mastered-products>
<!-- for each member of current group -->
<xsl:for-each select="key('groupbyproduct', product)">
<mastered-product sku="{sku}" domain="MasterRepository"/>
</xsl:for-each>
</mastered-products>
</variations>
</offer>
</xsl:for-each>
至于你的评论和你想要的完整结果,看起来好像是先分组然后在内部输出不同的数据应该给出你想要的顺序:
<xsl:for-each select="Products[count(. | key('groupbyproduct', product)[1]) = 1]">
<xsl:for-each select="key('groupbyproduct', product)">
<offer sku="{sku}">
<custom-attributes>
<custom-attribute name="parentcolour" dt:dt="string" xml:lang="en-US">
<xsl:value-of select="parentcolour_EN/text()"/>
</custom-attribute>
<custom-attribute name="parentcolour" dt:dt="string" xml:lang="de-DE">
<xsl:value-of select="parentcolour_DE/text()"/>
</custom-attribute>
</custom-attributes>
</offer>
</xsl:for-each>
<offer sku="{product}">
<variations>
<mastered-products>
<!-- for each member of current group -->
<xsl:for-each select="key('groupbyproduct', product)">
<mastered-product sku="{sku}" domain="MasterRepository"/>
</xsl:for-each>
</mastered-products>
</variations>
</offer>
</xsl:for-each>
我有以下 CSV 文件,XSD 看起来像这样:
123456|123456777|Green|Grün
123456|123456888|Red|Rot
987654|987654333|Yellow|Gelb
In XML format it looks like this:
<Product xmlns="http://F.FlatFileSchema1">
<Products xmlns="">
<product>123456</product>
<sku>123456777</sku>
<parentcolour_EN>Green</parentcolour_EN>
<parentcolour_DE>Grün</parentcolour_DE>
</Products>
<Products xmlns="">
<product>123456</product>
<sku>123456888</sku>
<parentcolour_EN>Red</parentcolour_EN>
<parentcolour_DE>Rot</parentcolour_DE>
</Products>
<Products xmlns="">
<product>987654</product>
<sku>987654333</sku>
<parentcolour_EN>Yellow</parentcolour_EN>
<parentcolour_DE>Gelb</parentcolour_DE>
</Products>
</Product>
目的是将其转换为具有以下格式的 xml:
<?xml version="1.0" encoding="utf-8"?>
<enfinity xsi:schemaLocation="http://www.intershop.com/xml/ns/enfinity/7.0/xcs/impex catalog.xsd http://www.intershop.com/xml/ns/enfinity/6.5/core/impex-dt dt.xsd" major="6" minor="1" family="enfinity" branch="enterprise" build="build" xmlns="http://www.intershop.com/xml/ns/enfinity/7.0/xcs/impex" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:dt="http://www.intershop.com/xml/ns/enfinity/6.5/core/impex-dt">
<offer sku="123456777">
<custom-attributes>
<custom-attribute name="parentcolour" dt:dt="string" xml:lang="en-US">Green</custom-attribute>
<custom-attribute name="parentcolour" dt:dt="string" xml:lang="de-DE">Grün</custom-attribute>
</custom-attributes>
</offer>
<offer sku="123456888">
<custom-attributes>
<custom-attribute name="parentcolour" dt:dt="string" xml:lang="en-US">Red</custom-attribute>
<custom-attribute name="parentcolour" dt:dt="string" xml:lang="de-DE">Rot</custom-attribute>
</custom-attributes>
</offer>
<offer sku="123456">
<variations>
<mastered-products>
<mastered-product sku="123456777" domain="MasterRepository"/>
<mastered-product sku="123456888" domain="MasterRepository"/>
</mastered-products>
</variations>
</offer>
<offer sku="987654333">
<custom-attributes>
<custom-attribute name="parentcolour" dt:dt="string" xml:lang="en-US">Yellow</custom-attribute>
<custom-attribute name="parentcolour" dt:dt="string" xml:lang="de-DE">Gelb</custom-attribute>
</custom-attributes>
</offer>
<offer sku="987654">
<variations>
<mastered-products>
<mastered-product sku="987654333" domain="MasterRepository"/>
</mastered-products>
</variations>
</offer>
</enfinity>
如您所见,XML中确实出现了所有 3 个 SKU,但还需要在 SKU 的末尾出现一个额外的产品,即 123456 出现在 123456777 和 123456888 之后,987654 出现在 987654333 之后. 到目前为止,我无法在应用 Muenchian 分组后显示产品级别的变化块。我当前的 XSL 如下所示:
<?xml version="1.0" encoding="UTF-16"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:s0="http://F.FlatFileSchema1" xmlns:xml="http://www.w3.org/XML/1998/namespace" exclude-result-prefixes="s0">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:key name="groupbyproduct" match="offer" use="product"/>
<xsl:template match="/s0:Product">
<enfinity xsi:schemaLocation="http://www.intershop.com/xml/ns/enfinity/7.0/xcs/impex catalog.xsd http://www.intershop.com/xml/ns/enfinity/6.5/core/impex-dt dt.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.intershop.com/xml/ns/enfinity/7.0/xcs/impex" xmlns:xml="http://www.w3.org/XML/1998/namespace" xmlns:dt="http://www.intershop.com/xml/ns/enfinity/6.5/core/impex-dt" major="6" minor="1" family="enfinity" branch="enterprise" build="build">
<xsl:for-each select="Products">
<offer sku="{sku}">
<custom-attributes>
<custom-attribute name="parentcolour" dt:dt="string" xml:lang="en-US">
<xsl:value-of select="parentcolour_EN/text()"/>
</custom-attribute>
<custom-attribute name="parentcolour" dt:dt="string" xml:lang="de-DE">
<xsl:value-of select="parentcolour_DE/text()"/>
</custom-attribute>
</custom-attributes>
</offer>
</xsl:for-each>
<!-- create a group for each unique product -->
<xsl:for-each select="offer[count(. | key('groupbyproduct', product)[1]) = 1]">
<offer sku="{product}">
<variations>
<mastered-products>
<!-- for each member of current group -->
<xsl:for-each select="key('groupbyproduct', product)">
<mastered-product sku="{sku}" domain="MasterRepository"/>
</xsl:for-each>
</mastered-products>
</variations>
</offer>
</xsl:for-each>
</enfinity>
</xsl:template>
</xsl:stylesheet>
密钥没有意义,我想你想要 <xsl:key name="groupbyproduct" match="Products" use="product"/>
然后你想要
for-each
<!-- create a group for each unique product -->
<xsl:for-each select="Products[count(. | key('groupbyproduct', product)[1]) = 1]">
<offer sku="{product}">
<variations>
<mastered-products>
<!-- for each member of current group -->
<xsl:for-each select="key('groupbyproduct', product)">
<mastered-product sku="{sku}" domain="MasterRepository"/>
</xsl:for-each>
</mastered-products>
</variations>
</offer>
</xsl:for-each>
至于你的评论和你想要的完整结果,看起来好像是先分组然后在内部输出不同的数据应该给出你想要的顺序:
<xsl:for-each select="Products[count(. | key('groupbyproduct', product)[1]) = 1]">
<xsl:for-each select="key('groupbyproduct', product)">
<offer sku="{sku}">
<custom-attributes>
<custom-attribute name="parentcolour" dt:dt="string" xml:lang="en-US">
<xsl:value-of select="parentcolour_EN/text()"/>
</custom-attribute>
<custom-attribute name="parentcolour" dt:dt="string" xml:lang="de-DE">
<xsl:value-of select="parentcolour_DE/text()"/>
</custom-attribute>
</custom-attributes>
</offer>
</xsl:for-each>
<offer sku="{product}">
<variations>
<mastered-products>
<!-- for each member of current group -->
<xsl:for-each select="key('groupbyproduct', product)">
<mastered-product sku="{sku}" domain="MasterRepository"/>
</xsl:for-each>
</mastered-products>
</variations>
</offer>
</xsl:for-each>