【发布时间】:2021-11-12 18:30:19
【问题描述】:
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>
正如您所见,所有 3 个 sku 都出现在 XML 中,但还需要在 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>
【问题讨论】:
-
请编辑您的问题并显示 XML 输入。
-
很抱歉应该包括这个,只是把它放在问题的顶部,提前非常感谢!
标签: xml xslt xsd biztalk muenchian-grouping