Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/xslt/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
XSLT 2.0在一个组中包含多个级别_Xslt - Fatal编程技术网

XSLT 2.0在一个组中包含多个级别

XSLT 2.0在一个组中包含多个级别,xslt,Xslt,问题是我如何获得期望的输出 我成功地为每个 但是,字段也必须用一个值填充。对于000094必须在要转换的xsl中用10 from10填充。而000072必须用20 from20填充,000032必须用35 from35 要转换的xml: <Test> <Product ID="LV-10432200" UserTypeID="CombiLogistiekeVariant"> <Name>1 - T

问题是我如何获得期望的输出

我成功地为每个
但是,
字段也必须用一个值填充。对于
000094
必须在要转换的xsl中用10 from
10
填充。而
000072
必须用20 from
20
填充,
000032
必须用35 from
35

要转换的xml:

<Test>
    <Product ID="LV-10432200" UserTypeID="CombiLogistiekeVariant">
        <Name>1 - TEST1</Name>
        <ProductCrossReference ProductID="Product-10430948"
            Type="rpp_CombiLogistiekeVariant2Product">
            <KeyValue KeyID="key_ProductGTIN">2311111</KeyValue>
            <KeyValue KeyID="key_Productnummer">000094</KeyValue>
            <MetaData>
                <Value AttributeID="att_AantalInCombiProduct">10</Value>
            </MetaData>
        </ProductCrossReference>
        <ProductCrossReference ProductID="Product-10431710"
            Type="rpp_CombiLogistiekeVariant2Product">
            <KeyValue KeyID="key_ProductGTIN">5449000018885</KeyValue>
            <KeyValue KeyID="key_Productnummer">000072</KeyValue>
            <MetaData>
                <Value AttributeID="att_AantalInCombiProduct">20</Value>
            </MetaData>
        </ProductCrossReference>
        <ProductCrossReference ProductID="Product-10431738"
            Type="rpp_CombiLogistiekeVariant2Product">
            <KeyValue KeyID="key_ProductGTIN">54419780</KeyValue>
            <KeyValue KeyID="key_Productnummer">000032</KeyValue>
            <MetaData>
                <Value AttributeID="att_AantalInCombiProduct" Changed="true">35
                </Value>
            </MetaData>
        </ProductCrossReference>
        <Values>
            <Value AttributeID="att_Productnummer">000001</Value>
            <Value AttributeID="att_LVStatus" ID="2">Inactief</Value>
            <Value AttributeID="att_LVOmschrijving">TEST Config 1</Value>
            <Value AttributeID="att_LVNummer">1</Value>
        </Values>
        <Product ID="Pack-10432212" UserTypeID="Kleinverpakking">
            <Name>21 - Kleinverpakking</Name>
            <ProductCrossReference ProductID="LV-10432200"
                Type="rpp_Verpakking-Kleinverpakking2Kleiner">
                <MetaData>
                    <Value AttributeID="att_AantalInVerpakking">1</Value>
                </MetaData>
            </ProductCrossReference>
            <Values>
                <Value AttributeID="att_VerpakkingBreedte" UnitID="unece.unit.CMT">1</Value>
                <Value AttributeID="att_VerpakkingGewichtBruto" UnitID="181">1
                </Value>
                <Value AttributeID="att_LVNummer">1</Value>
                <Value AttributeID="att_VerpakkingHoogte" UnitID="unece.unit.CMT">1</Value>
                <Value AttributeID="att_Productnummer">000001</Value>
                <Value AttributeID="att_VerpakkingDiepte" UnitID="unece.unit.CMT">1</Value>
                <Value AttributeID="att_PrimaireGTIN" Derived="true">Primaire GTIN
                    Ontbreekt
                </Value>
            </Values>
        </Product>
    </Product>
</Test> 

1-测试1
2311111
000094
10
5449000018885
000072
20
54419780
000032
35
000001
无为
测试配置1
1.
21-克莱因弗帕克金
1.
1.
1.
1.
1.
000001
1.
Primaire GTIN
安特布里克特
必须转变为:

                    <LogistiekeDeelEenheid>
                        <DeeleenheidArtikelNummer>000094</DeeleenheidArtikelNummer>
                        <DeeleenheidLogistiekeVariant>0</DeeleenheidLogistiekeVariant>
                        <DeeleenheidCode>1</DeeleenheidCode>
                        <DeeleenheidLinkType>4</DeeleenheidLinkType>
                        <DeeleenheidAantal>10</DeeleenheidAantal>
                    </LogistiekeDeelEenheid>
                    <LogistiekeDeelEenheid>
                        <DeeleenheidArtikelNummer>000072</DeeleenheidArtikelNummer>
                        <DeeleenheidLogistiekeVariant>0</DeeleenheidLogistiekeVariant>
                        <DeeleenheidCode>1</DeeleenheidCode>
                        <DeeleenheidLinkType>4</DeeleenheidLinkType>
                        <DeeleenheidAantal>20</DeeleenheidAantal>
                    </LogistiekeDeelEenheid>
                    <LogistiekeDeelEenheid>
                        <DeeleenheidArtikelNummer>000032</DeeleenheidArtikelNummer>
                        <DeeleenheidLogistiekeVariant>0</DeeleenheidLogistiekeVariant>
                        <DeeleenheidCode>1</DeeleenheidCode>
                        <DeeleenheidLinkType>4</DeeleenheidLinkType>
                        <DeeleenheidAantal>35</DeeleenheidAantal>
                    </LogistiekeDeelEenheid>
               

000094
0
1.
4.
10
000072
0
1.
4.
20
000032
0
1.
4.
35
我的xslt:

<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
            <xsl:output encoding="UTF-8" indent="yes" method="xml"/>
    <xsl:template match="/">
        <xsl:apply-templates select="Test/Product"/>
    </xsl:template>
        <xsl:template match="Test/Product">
            <xsl:for-each-group select="//ProductCrossReference[@Type='rpp_CombiLogistiekeVariant2Product']" group-by="//ProductCrossReference/KeyValue[@KeyID='key_Productnummer']">
            <xsl:variable select="current-grouping-key()" name="Productnummer"/>
       <test>
           <xsl:value-of select="../Name"/>
       </test>
        <LogistiekeDeelEenheid>
            <DeeleenheidArtikelNummer>
                <xsl:value-of select="$Productnummer"/>
            </DeeleenheidArtikelNummer>
            <DeeleenheidLogistiekeVariant>0</DeeleenheidLogistiekeVariant>
            <DeeleenheidCode>1</DeeleenheidCode>
            <DeeleenheidLinkType>4</DeeleenheidLinkType>
            <DeeleenheidAantal>
                <xsl:value-of select="../ProductCrossReference/MetaData/Value[@AttributeID='att_AantalInCombiProduct']"/>
            </DeeleenheidAantal>
        </LogistiekeDeelEenheid>
    </xsl:for-each-group>
        </xsl:template>
</xsl:stylesheet>

0
1.
4.
但是如果我使用这个代码,我得到的结果是不正确的。第一个应该是10,第二个是20,第三个是35

<?xml encoding="UTF-8" version="1.0"?>
<test>1 - TEST1</test>
<LogistiekeDeelEenheid>
   <DeeleenheidArtikelNummer>000094</DeeleenheidArtikelNummer>
   <DeeleenheidLogistiekeVariant>0</DeeleenheidLogistiekeVariant>
   <DeeleenheidCode>1</DeeleenheidCode>
   <DeeleenheidLinkType>4</DeeleenheidLinkType>
   <DeeleenheidAantal>10 20 35
                </DeeleenheidAantal>
</LogistiekeDeelEenheid>
<test>1 - TEST1</test>
<LogistiekeDeelEenheid>
   <DeeleenheidArtikelNummer>000072</DeeleenheidArtikelNummer>
   <DeeleenheidLogistiekeVariant>0</DeeleenheidLogistiekeVariant>
   <DeeleenheidCode>1</DeeleenheidCode>
   <DeeleenheidLinkType>4</DeeleenheidLinkType>
   <DeeleenheidAantal>10 20 35
                </DeeleenheidAantal>
</LogistiekeDeelEenheid>
<test>1 - TEST1</test>
<LogistiekeDeelEenheid>
   <DeeleenheidArtikelNummer>000032</DeeleenheidArtikelNummer>
   <DeeleenheidLogistiekeVariant>0</DeeleenheidLogistiekeVariant>
   <DeeleenheidCode>1</DeeleenheidCode>
   <DeeleenheidLinkType>4</DeeleenheidLinkType>
   <DeeleenheidAantal>10 20 35
                </DeeleenheidAantal>
</LogistiekeDeelEenheid>

1-测试1
000094
0
1.
4.
10 20 35
1-测试1
000072
0
1.
4.
10 20 35
1-测试1
000032
0
1.
4.
10 20 35

我在评论中提出的建议,根据您稍后发布的代码进行了调整,将导致

    <xsl:template match="Test/Product">
        <xsl:for-each-group select="ProductCrossReference[@Type='rpp_CombiLogistiekeVariant2Product']" 
        group-by="KeyValue[@KeyID='key_Productnummer']">
        <xsl:variable select="current-grouping-key()" name="Productnummer"/>
   <test>
       <xsl:value-of select="../Name"/>
   </test>
    <LogistiekeDeelEenheid>
        <DeeleenheidArtikelNummer>
            <xsl:value-of select="$Productnummer"/>
        </DeeleenheidArtikelNummer>
        <DeeleenheidLogistiekeVariant>0</DeeleenheidLogistiekeVariant>
        <DeeleenheidCode>1</DeeleenheidCode>
        <DeeleenheidLinkType>4</DeeleenheidLinkType>
        <DeeleenheidAantal>
            <xsl:value-of select="MetaData/Value[@AttributeID='att_AantalInCombiProduct']"/>
        </DeeleenheidAantal>
    </LogistiekeDeelEenheid>
</xsl:for-each-group>
    </xsl:template>

0
1.
4.
至少,我将建议应用于您编辑的输入样本,结果具有例如
10
,即结果中该项的单个值


我必须承认,我仍然不清楚您的嵌套样本数据,但请随意进一步编辑您的问题,并澄清您要处理和分组的数据。

考虑将样本数据削减到最低限度,以演示问题,并口头描述您要实现的目标。不起作用的XSLT片段不足以实现您想要实现的目标。@MartinHonnen,我已经调整了我的问题/示例数据。希望它是清楚的,但事实并非如此。请将您的代码减少到再现问题并使其完整所需的最低限度,即可以复制并按原样运行的代码。请参阅:。不太清楚您为什么说要分组,但
xsl:for each group select=“(../../Product[@UserTypeID='CombiLogistiekeVariant'])[1]”
似乎选择了单个元素作为分组填充。在示例数据中,键表达式
ProductCrossReference/KeyValue[@KeyID='key\u Productnummer']
似乎不会给出任何重复项。因此,似乎根本不需要分组,而是直接处理
ProductCrossReference
元素。或者将它们分组,而不是单个产品,然后选择
MetaData/Value[@AttributeID='attt_AantalInCombiProduct']
。我已经调整了示例,因此这是复制的最小值。我知道它不适合使用//但是现在…它只是整个XSLT的一小部分感谢您的帮助。对于这一部分,我很高兴。现在我必须让它在整个xslt中工作,是的,xml中有很多嵌套。我必须处理这件事,别无选择。