xsl:for-每个循环都在复制我不期望的东西

xsl:for-each Loop is duplicating things I am not expecting

(使用 XSLT 1.0 和 运行 通过 FOP 1.1) 砍掉XML

<?xml version="1.0"?>
<Report schema="1.01">
    <Item id="1" name="cabinet">
        <VSection id="0" vsection="main">
            <HSection id="22">
                <Component id="1" idfull="00102201">
                    <DisplayName>Board</DisplayName>
                    <Category>Carcass</Category>
                    <Brand>Melamine</Brand>
                    <Color>Black</Color>
                    <Finish></Finish>
                    <Material>16mm Black</Material>
                    <Style></Style>
                    <PartNo></PartNo>
                    <Comment>End-R</Comment>
                    <Optimising></Optimising>
                    <IsOptimised>No</IsOptimised>
                    <IsGrained>No</IsGrained>
                    <IsRecutPanel>No</IsRecutPanel>
                    <IsRecutPiece>No</IsRecutPiece>
                    <Boring></Boring>
                    <Edging>1L</Edging>
                    <IsEdgedOnTop>No</IsEdgedOnTop>
                    <IsEdgedOnRight>No</IsEdgedOnRight>
                    <IsEdgedOnBottom>No</IsEdgedOnBottom>
                    <IsEdgedOnLeft>Yes</IsEdgedOnLeft>
                    <EdgeMatTop></EdgeMatTop>
                    <EdgeMatRight></EdgeMatRight>
                    <EdgeMatBottom></EdgeMatBottom>
                    <EdgeMatLeft>1mm</EdgeMatLeft>
                    <Hinging></Hinging>
                    <HingePos>Outside</HingePos>
                    <IsPresent>Yes</IsPresent>
                    <IsStock>No</IsStock>
                    <Label></Label>
                    <DimName1>16mm Black</DimName1>
                    <Dim1>720mm</Dim1>
                    <DimCut1>720mm</DimCut1>
                    <DimName2>Width</DimName2>
                    <Dim2>560mm</Dim2>
                    <DimCut2>559mm</DimCut2>
                    <DimName3>Thickness</DimName3>
                    <Dim3>16mm</Dim3>
                    <DimCut3>16mm</DimCut3>
                    <Time>0.00mn</Time>
                    <UnitCost>[=11=].00</UnitCost>
                    <Cost>[=11=].00</Cost>
                    <UnitSell>[=11=].00</UnitSell>
                    <Sell>[=11=].00</Sell>
                    <Quantity>1</Quantity>
                </Component>
            </HSection>
            <HSection id="33">
                <Component id="1" idfull="00103301">
                    <DisplayName>Board</DisplayName>
                    <Category>Carcass</Category>
                    <Brand>Melamine</Brand>
                    <Color>White</Color>
                    <Finish></Finish>
                    <Material>16mm White HMR</Material>
                    <Style></Style>
                    <PartNo></PartNo>
                    <Comment>Shelf Adj</Comment>
                    <Optimising></Optimising>
                    <IsOptimised>No</IsOptimised>
                    <IsGrained>No</IsGrained>
                    <IsRecutPanel>No</IsRecutPanel>
                    <IsRecutPiece>No</IsRecutPiece>
                    <Boring></Boring>
                    <Edging>1L</Edging>
                    <IsEdgedOnTop>No</IsEdgedOnTop>
                    <IsEdgedOnRight>Yes</IsEdgedOnRight>
                    <IsEdgedOnBottom>No</IsEdgedOnBottom>
                    <IsEdgedOnLeft>No</IsEdgedOnLeft>
                    <EdgeMatTop></EdgeMatTop>
                    <EdgeMatRight>1mm</EdgeMatRight>
                    <EdgeMatBottom></EdgeMatBottom>
                    <EdgeMatLeft></EdgeMatLeft>
                    <Hinging></Hinging>
                    <HingePos>Outside</HingePos>
                    <IsPresent>Yes</IsPresent>
                    <IsStock>No</IsStock>
                    <Label></Label>
                    <DimName1>_16.0mm Carcase White</DimName1>
                    <Dim1>816mm</Dim1>
                    <DimCut1>816mm</DimCut1>
                    <DimName2>Width</DimName2>
                    <Dim2>533mm</Dim2>
                    <DimCut2>532mm</DimCut2>
                    <DimName3>Thickness</DimName3>
                    <Dim3>16mm</Dim3>
                    <DimCut3>16mm</DimCut3>
                    <Time>0.00mn</Time>
                    <UnitCost>[=11=].00</UnitCost>
                    <Cost>[=11=].00</Cost>
                    <UnitSell>[=11=].00</UnitSell>
                    <Sell>[=11=].00</Sell>
                    <Quantity>1</Quantity>
                </Component>
                </HSection>
            <HSection id="18">
                <Component id="1" idfull="00101801">
                    <DisplayName>Board</DisplayName>
                    <Category>Carcass</Category>
                    <Brand>Melamine</Brand>
                    <Color>Black</Color>
                    <Finish></Finish>
                    <Material>16mm Black</Material>
                    <Style></Style>
                    <PartNo></PartNo>
                    <Comment>End-L</Comment>
                    <Optimising></Optimising>
                    <IsOptimised>No</IsOptimised>
                    <IsGrained>No</IsGrained>
                    <IsRecutPanel>No</IsRecutPanel>
                    <IsRecutPiece>No</IsRecutPiece>
                    <Boring></Boring>
                    <Edging>1L</Edging>
                    <IsEdgedOnTop>No</IsEdgedOnTop>
                    <IsEdgedOnRight>Yes</IsEdgedOnRight>
                    <IsEdgedOnBottom>No</IsEdgedOnBottom>
                    <IsEdgedOnLeft>No</IsEdgedOnLeft>
                    <EdgeMatTop></EdgeMatTop>
                    <EdgeMatRight>1mm</EdgeMatRight>
                    <EdgeMatBottom></EdgeMatBottom>
                    <EdgeMatLeft></EdgeMatLeft>
                    <Hinging></Hinging>
                    <HingePos>Outside</HingePos>
                    <IsPresent>Yes</IsPresent>
                    <IsStock>No</IsStock>
                    <Label></Label>
                    <DimName1>16mm Black</DimName1>
                    <Dim1>720mm</Dim1>
                    <DimCut1>720mm</DimCut1>
                    <DimName2>Width</DimName2>
                    <Dim2>560mm</Dim2>
                    <DimCut2>559mm</DimCut2>
                    <DimName3>Thickness</DimName3>
                    <Dim3>16mm</Dim3>
                    <DimCut3>16mm</DimCut3>
                    <Time>0.00mn</Time>
                    <UnitCost>[=11=].00</UnitCost>
                    <Cost>[=11=].00</Cost>
                    <UnitSell>[=11=].00</UnitSell>
                    <Sell>[=11=].00</Sell>
                    <Quantity>1</Quantity>
                </Component>
                </HSection>
            <HSection id="15">
                <Component id="1" idfull="00101501">
                    <DisplayName>Board</DisplayName>
                    <Category>Carcass</Category>
                    <Brand>Melamine</Brand>
                    <Color>White</Color>
                    <Finish></Finish>
                    <Material>16mm White HMR</Material>
                    <Style></Style>
                    <PartNo></PartNo>
                    <Comment>Bottom</Comment>
                    <Optimising></Optimising>
                    <IsOptimised>No</IsOptimised>
                    <IsGrained>No</IsGrained>
                    <IsRecutPanel>No</IsRecutPanel>
                    <IsRecutPiece>No</IsRecutPiece>
                    <Boring></Boring>
                    <Edging>1L</Edging>
                    <IsEdgedOnTop>No</IsEdgedOnTop>
                    <IsEdgedOnRight>Yes</IsEdgedOnRight>
                    <IsEdgedOnBottom>No</IsEdgedOnBottom>
                    <IsEdgedOnLeft>No</IsEdgedOnLeft>
                    <EdgeMatTop></EdgeMatTop>
                    <EdgeMatRight>1mm</EdgeMatRight>
                    <EdgeMatBottom></EdgeMatBottom>
                    <EdgeMatLeft></EdgeMatLeft>
                    <Hinging></Hinging>
                    <HingePos>Outside</HingePos>
                    <IsPresent>Yes</IsPresent>
                    <IsStock>No</IsStock>
                    <Label></Label>
                    <DimName1>_16.0mm Carcase White</DimName1>
                    <Dim1>818mm</Dim1>
                    <DimCut1>818mm</DimCut1>
                    <DimName2>Width</DimName2>
                    <Dim2>544mm</Dim2>
                    <DimCut2>543mm</DimCut2>
                    <DimName3>Thickness</DimName3>
                    <Dim3>16mm</Dim3>
                    <DimCut3>16mm</DimCut3>
                    <Time>0.00mn</Time>
                    <UnitCost>[=11=].00</UnitCost>
                    <Cost>[=11=].00</Cost>
                    <UnitSell>[=11=].00</UnitSell>
                    <Sell>[=11=].00</Sell>
                    <Quantity>1</Quantity>
                </Component>
                </HSection>
            <HSection id="30">
                <Component id="1" idfull="00103001">
                    <DisplayName>Board</DisplayName>
                    <Category>Carcass</Category>
                    <Brand>Melamine</Brand>
                    <Color>White</Color>
                    <Finish></Finish>
                    <Material>16mm White HMR</Material>
                    <Style></Style>
                    <PartNo></PartNo>
                    <Comment>Shelf Adj</Comment>
                    <Optimising></Optimising>
                    <IsOptimised>No</IsOptimised>
                    <IsGrained>No</IsGrained>
                    <IsRecutPanel>No</IsRecutPanel>
                    <IsRecutPiece>No</IsRecutPiece>
                    <Boring></Boring>
                    <Edging>1L</Edging>
                    <IsEdgedOnTop>No</IsEdgedOnTop>
                    <IsEdgedOnRight>Yes</IsEdgedOnRight>
                    <IsEdgedOnBottom>No</IsEdgedOnBottom>
                    <IsEdgedOnLeft>No</IsEdgedOnLeft>
                    <EdgeMatTop></EdgeMatTop>
                    <EdgeMatRight>1mm</EdgeMatRight>
                    <EdgeMatBottom></EdgeMatBottom>
                    <EdgeMatLeft></EdgeMatLeft>
                    <Hinging></Hinging>
                    <HingePos>Outside</HingePos>
                    <IsPresent>Yes</IsPresent>
                    <IsStock>No</IsStock>
                    <Label></Label>
                    <DimName1>_16.0mm Carcase White</DimName1>
                    <Dim1>816mm</Dim1>
                    <DimCut1>816mm</DimCut1>
                    <DimName2>Width</DimName2>
                    <Dim2>533mm</Dim2>
                    <DimCut2>532mm</DimCut2>
                    <DimName3>Thickness</DimName3>
                    <Dim3>16mm</Dim3>
                    <DimCut3>16mm</DimCut3>
                    <Time>0.00mn</Time>
                    <UnitCost>[=11=].00</UnitCost>
                    <Cost>[=11=].00</Cost>
                    <UnitSell>[=11=].00</UnitSell>
                    <Sell>[=11=].00</Sell>
                    <Quantity>1</Quantity>
                </Component>
                </HSection>
            <HSection id="39">
                <Component id="1" idfull="00103901">
                    <DisplayName>Board</DisplayName>
                    <Category>Carcass</Category>
                    <Brand>Melamine</Brand>
                    <Color>Black</Color>
                    <Finish></Finish>
                    <Material>16mm Black</Material>
                    <Style></Style>
                    <PartNo></PartNo>
                    <Comment>Top</Comment>
                    <Optimising></Optimising>
                    <IsOptimised>No</IsOptimised>
                    <IsGrained>No</IsGrained>
                    <IsRecutPanel>No</IsRecutPanel>
                    <IsRecutPiece>No</IsRecutPiece>
                    <Boring></Boring>
                    <Edging>1L</Edging>
                    <IsEdgedOnTop>No</IsEdgedOnTop>
                    <IsEdgedOnRight>Yes</IsEdgedOnRight>
                    <IsEdgedOnBottom>No</IsEdgedOnBottom>
                    <IsEdgedOnLeft>No</IsEdgedOnLeft>
                    <EdgeMatTop></EdgeMatTop>
                    <EdgeMatRight>1mm</EdgeMatRight>
                    <EdgeMatBottom></EdgeMatBottom>
                    <EdgeMatLeft></EdgeMatLeft>
                    <Hinging></Hinging>
                    <HingePos>Outside</HingePos>
                    <IsPresent>Yes</IsPresent>
                    <IsStock>No</IsStock>
                    <Label></Label>
                    <DimName1>16mm Black</DimName1>
                    <Dim1>818mm</Dim1>
                    <DimCut1>818mm</DimCut1>
                    <DimName2>Width</DimName2>
                    <Dim2>544mm</Dim2>
                    <DimCut2>543mm</DimCut2>
                    <DimName3>Thickness</DimName3>
                    <Dim3>16mm</Dim3>
                    <DimCut3>16mm</DimCut3>
                    <Time>0.00mn</Time>
                    <UnitCost>[=11=].00</UnitCost>
                    <Cost>[=11=].00</Cost>
                    <UnitSell>[=11=].00</UnitSell>
                    <Sell>[=11=].00</Sell>
                    <Quantity>1</Quantity>
                </Component>
                </HSection>
            <HSection id="10">
                <Component id="1" idfull="00101001">
                    <DisplayName>Board</DisplayName>
                    <Category>Carcass</Category>
                    <Brand>Melamine</Brand>
                    <Color>White</Color>
                    <Finish></Finish>
                    <Material>16mm White HMR</Material>
                    <Style></Style>
                    <PartNo></PartNo>
                    <Comment>Back</Comment>
                    <Optimising></Optimising>
                    <IsOptimised>No</IsOptimised>
                    <IsGrained>No</IsGrained>
                    <IsRecutPanel>Yes</IsRecutPanel>
                    <IsRecutPiece>No</IsRecutPiece>
                    <Boring></Boring>
                    <Edging></Edging>
                    <IsEdgedOnTop>No</IsEdgedOnTop>
                    <IsEdgedOnRight>No</IsEdgedOnRight>
                    <IsEdgedOnBottom>No</IsEdgedOnBottom>
                    <IsEdgedOnLeft>No</IsEdgedOnLeft>
                    <EdgeMatTop></EdgeMatTop>
                    <EdgeMatRight></EdgeMatRight>
                    <EdgeMatBottom></EdgeMatBottom>
                    <EdgeMatLeft></EdgeMatLeft>
                    <Hinging></Hinging>
                    <HingePos>Outside</HingePos>
                    <IsPresent>Yes</IsPresent>
                    <IsStock>No</IsStock>
                    <Label></Label>
                    <DimName1>_16.0mm Carcase White</DimName1>
                    <Dim1>720mm</Dim1>
                    <DimCut1>720mm</DimCut1>
                    <DimName2>Width</DimName2>
                    <Dim2>818mm</Dim2>
                    <DimCut2>818mm</DimCut2>
                    <DimName3>Thickness</DimName3>
                    <Dim3>16mm</Dim3>
                    <DimCut3>16mm</DimCut3>
                    <Time>0.00mn</Time>
                    <UnitCost>[=11=].00</UnitCost>
                    <Cost>[=11=].00</Cost>
                    <UnitSell>[=11=].00</UnitSell>
                    <Sell>[=11=].00</Sell>
                    <Quantity>1</Quantity>
                </Component>
                </HSection>
            <HSection id="36">
                <Component id="1" idfull="00103601">
                    <DisplayName>Board</DisplayName>
                    <Category>Carcass</Category>
                    <Brand>Melamine</Brand>
                    <Color>White</Color>
                    <Finish></Finish>
                    <Material>16mm White HMR</Material>
                    <Style></Style>
                    <PartNo></PartNo>
                    <Comment>Shelf Adj</Comment>
                    <Optimising></Optimising>
                    <IsOptimised>No</IsOptimised>
                    <IsGrained>No</IsGrained>
                    <IsRecutPanel>No</IsRecutPanel>
                    <IsRecutPiece>No</IsRecutPiece>
                    <Boring></Boring>
                    <Edging>1L</Edging>
                    <IsEdgedOnTop>No</IsEdgedOnTop>
                    <IsEdgedOnRight>Yes</IsEdgedOnRight>
                    <IsEdgedOnBottom>No</IsEdgedOnBottom>
                    <IsEdgedOnLeft>No</IsEdgedOnLeft>
                    <EdgeMatTop></EdgeMatTop>
                    <EdgeMatRight>1mm</EdgeMatRight>
                    <EdgeMatBottom></EdgeMatBottom>
                    <EdgeMatLeft></EdgeMatLeft>
                    <Hinging></Hinging>
                    <HingePos>Outside</HingePos>
                    <IsPresent>Yes</IsPresent>
                    <IsStock>No</IsStock>
                    <Label></Label>
                    <DimName1>_16.0mm Carcase White</DimName1>
                    <Dim1>816mm</Dim1>
                    <DimCut1>816mm</DimCut1>
                    <DimName2>Width</DimName2>
                    <Dim2>533mm</Dim2>
                    <DimCut2>532mm</DimCut2>
                    <DimName3>Thickness</DimName3>
                    <Dim3>16mm</Dim3>
                    <DimCut3>16mm</DimCut3>
                    <Time>0.00mn</Time>
                    <UnitCost>[=11=].00</UnitCost>
                    <Cost>[=11=].00</Cost>
                    <UnitSell>[=11=].00</UnitSell>
                    <Sell>[=11=].00</Sell>
                    <Quantity>1</Quantity>
                </Component>
                </HSection>
        </VSection>
    </Item>
</Report>

下面是会产生意外重复的缩短的 XSL:FO。

    <?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"
                        xmlns:fo="http://www.w3.org/1999/XSL/Format">
<xsl:output indent="yes" method="xml" encoding="iso-8859-1"/>   

<xsl:key name="cMaterial" match="Component[DisplayName='Board'][Category='Carcass']" use="concat(generate-id(../../..),'+',Material,'+',Color,'+',DimCut3)" />
<xsl:key name="UcMaterial" match="Component[DisplayName='Board'][Category='Carcass']" use="concat(generate-id(../../..),'+',Material,'+',Color,'+',DimCut3,'+',DimCut2,'+',DimCut1,'+',Comment,'+',Edging,'+',Quantity)" />


<xsl:template match="/">
    <fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">
        <!-- defines page layout -->
        <fo:layout-master-set>
            <fo:simple-page-master master-name="first-page"
                    page-height="29.7cm"
                    page-width="21cm">
            <fo:region-body margin-top="2cm" margin-bottom="1.5cm"/>
            </fo:simple-page-master>
            <fo:simple-page-master master-name="other-pages"
                    page-height="29.7cm"
                    page-width="21cm">
            <fo:region-body margin-top="0cm" margin-bottom="1.5cm"/>
            <fo:region-before extent="1cm" region-name="other-pages-header"/>
            <fo:region-after extent="1.0cm"/>
            </fo:simple-page-master>

            <fo:page-sequence-master master-name="pages">
                <fo:repeatable-page-master-alternatives>
                    <fo:conditional-page-master-reference page-position="first" master-reference="first-page"/>
                    <fo:conditional-page-master-reference master-reference="other-pages"/>
                </fo:repeatable-page-master-alternatives>
            </fo:page-sequence-master>

        </fo:layout-master-set>

        <fo:page-sequence master-reference="pages">

            <fo:flow flow-name="xsl-region-body">
                <fo:table>
                    <fo:table-column column-number="1" column-width="100%" />
                    <fo:table-body>
                        <fo:table-row>
                            <fo:table-cell><xsl:apply-templates select="Report/Item"/></fo:table-cell>
                        </fo:table-row>
                    </fo:table-body>
                </fo:table>
                <fo:block id="LastPage"/>
            </fo:flow>
        </fo:page-sequence>
    </fo:root>
</xsl:template>

 <xsl:template match="Item">
    <xsl:variable name="carcass" select="VSection/HSection/Component[key('UcMaterial',concat(generate-id(../../..),'+',Material,'+',Color,'+',DimCut3,'+',DimCut2,'+',DimCut1,'+',Comment,'+',Edging,'+',Quantity))]" />
    <fo:table keep-together="always">
        <fo:table-column column-number="1" column-width="100%" />
        <fo:table-body>
            <fo:table-row>
                <fo:table-cell>
                    <xsl:if test="count($carcass) > 0">
                    <fo:table>
                        <fo:table-column column-number="1" column-width="40%" />
                        <fo:table-column column-number="2" column-width="10%" />
                        <fo:table-column column-number="3" column-width="15%" />
                        <fo:table-column column-number="4" column-width="15%" />
                        <fo:table-column column-number="5" column-width="10%" />
                        <fo:table-column column-number="6" column-width="10%" />
                        <fo:table-body>
                            <fo:table-row>
                                <fo:table-cell number-columns-spanned="6"><fo:block>Carcass</fo:block></fo:table-cell>
                            </fo:table-row>
                            <xsl:for-each select="VSection/HSection/Component[generate-id()=generate-id(key('cMaterial',concat(generate-id(../../..),'+',Material,'+',Color,'+',DimCut3))[1])]">
                                <xsl:variable name="this" select="." />
                                <fo:table-row>
                                    <!-- 1 --><fo:table-cell number-columns-spanned="4">
                                                        <fo:block>
                                                            <xsl:value-of select="Material" /><xsl:text>: </xsl:text>
                                                            <xsl:value-of select="Color" /><xsl:text>: </xsl:text>
                                                            <xsl:value-of select="DimCut3" />
                                                        </fo:block>
                                                    </fo:table-cell>
                                    <!-- 5 --><fo:table-cell><fo:block></fo:block></fo:table-cell>
                                    <!-- 6 --><fo:table-cell><fo:block></fo:block></fo:table-cell>
                                </fo:table-row>
                                    <xsl:for-each select="key('cMaterial',concat(generate-id(../../..),'+',$this/Material,'+',$this/Color,'+',$this/DimCut3))">
                                        <xsl:sort select="Comment" />
                                        <xsl:variable name="similar" select="key('UcMaterial',concat(generate-id(../../..),'+',Material,'+',Color,'+',DimCut3,'+',DimCut2,'+',DimCut1,'+',Comment,'+',Edging,'+',Quantity))" />
                                        <xsl:for-each select="../Component[generate-id()=generate-id(key('UcMaterial',concat(generate-id(../../..),'+',Material,'+',Color,'+',DimCut3,'+',DimCut2,'+',DimCut1,'+',Comment,'+',Edging,'+',Quantity))[1])]">
                                            <fo:table-row>
                                                <!-- 1 --><fo:table-cell><fo:block><xsl:value-of select="Comment" /></fo:block></fo:table-cell>
                                                <!-- 2 --><fo:table-cell><fo:block><xsl:value-of select="sum($similar/Quantity)" />@</fo:block></fo:table-cell>
                                                <!-- 3 --><fo:table-cell><fo:block><xsl:value-of select="DimCut1" /></fo:block></fo:table-cell>
                                                <!-- 4 --><fo:table-cell><fo:block><xsl:value-of select="DimCut2" /></fo:block></fo:table-cell>
                                                <!-- 5 --><fo:table-cell><fo:block></fo:block></fo:table-cell>
                                                <!-- 6 --><fo:table-cell><fo:block></fo:block></fo:table-cell>
                                            </fo:table-row>
                                        </xsl:for-each>
                                    </xsl:for-each>
                            </xsl:for-each>
                        </fo:table-body>
                    </fo:table>
                    </xsl:if>
                </fo:table-cell>
            </fo:table-row>
        </fo:table-body>
    </fo:table>
 </xsl:template>
</xsl:stylesheet>

我的预期结果是看到下面的 table 形式...

6mm Black
EnL 1@ 300mm 400mm 1L
EnR 1@ 300mm 400mm 1L
Shelf 1@ 250mm 388mm 1L

6mm White
Back 1@ 300mm 400mm 1L
Bottom 1@ 294mm 388mm 1L
Shelf 2@ 250mm 388mm 1L
Top 1@ 294mm 388mm 1L

但我看到的是:

6mm Black
EnL 1@ 300mm 400mm 1L
EnR 1@ 300mm 400mm 1L
Shelf 1@ 250mm 388mm 1L

6mm White
Back 1@ 300mm 400mm 1L
Bottom 1@ 294mm 388mm 1L
Shelf 2@ 250mm 388mm 1L
Top 1@ 294mm 388mm 1L

6mm Black
EnL 1@ 300mm 400mm 1L
EnR 1@ 300mm 400mm 1L
Shelf 1@ 250mm 388mm 1L

6mm White
Back 1@ 300mm 400mm 1L
Bottom 1@ 294mm 388mm 1L
Shelf 2@ 250mm 388mm 1L
Top 1@ 294mm 388mm 1L

问题是为什么它会重复任务,我似乎无法理解 <for-each> 循环比我预期的要多。

(这个转换的原始方法来自这个问题,)

这似乎是 Xalan 处理器中的错误。它由

触发
<xsl:sort select="Comment" />

第 86 行的说明。如果您删除它,重复项将消失。

我应该补充一点,我并没有试图理解您的代码,但在我看来它可以大大简化。也许这也可以防止 bug 出现。

已从内部来源向我提供了解决方法,但它仍然没有改变@Micahael.hor257k 的答案是正确的事实。

如果我们使用;

<xsl:key name="cMaterial" match="Component[DisplayName='Board'][Category='Carcass']" use="concat(generate-id(../../..),'+',Material,'+',Color,'+',DimCut3)" />
<xsl:key name="UcMaterial" match="Component[DisplayName='Board'][Category='Carcass']" use="concat(generate-id(../../..),'+',Material,'+',Color,'+',DimCut3,'+',DimCut2,'+',DimCut1,'+',Comment,'+',Edging,'+',Quantity)" />

然后我们需要做的是使用第一个key的另一个key()在循环中使用,以防止重复发生,就像这样。

<xsl:key name="cMaterial" match="Component[DisplayName='Board'][Category='Carcass']" use="concat(generate-id(../../..),'+',Material,'+',Color,'+',DimCut3)" />
<xsl:key name="cMaterial2" match="Component[DisplayName='Board'][Category='Carcass']" use="concat(generate-id(../../..),'+',Material,'+',Color,'+',DimCut3)" />
    <xsl:key name="UcMaterial" match="Component[DisplayName='Board'][Category='Carcass']" use="concat(generate-id(../../..),'+',Material,'+',Color,'+',DimCut3,'+',DimCut2,'+',DimCut1,'+',Comment,'+',Edging,'+',Quantity)" />

现在在 XSL 中我们可以稍微更改代码以阅读下面的片段;

<xsl:for-each select="VSection/HSection/Component[generate-id()=generate-id(key('cMaterial',concat(generate-id(../../..),'+',Material,'+',Color,'+',DimCut3))[1])]">
                                <xsl:variable name="this" select="." />
                                <fo:table-row>
                                    <!-- 1 --><fo:table-cell number-columns-spanned="4">
                                                        <fo:block>
                                                            <xsl:value-of select="Material" /><xsl:text>: </xsl:text>
                                                            <xsl:value-of select="Color" /><xsl:text>: </xsl:text>
                                                            <xsl:value-of select="DimCut3" />
                                                        </fo:block>
                                                    </fo:table-cell>
                                    <!-- 5 --><fo:table-cell><fo:block></fo:block></fo:table-cell>
                                    <!-- 6 --><fo:table-cell><fo:block></fo:block></fo:table-cell>
                                </fo:table-row>
                                    <xsl:for-each select="key('cMaterial2',concat(generate-id(../../..),'+',$this/Material,'+',$this/Color,'+',$this/DimCut3))">
                                        <xsl:sort select="Comment" />
                                        <xsl:variable name="similar" select="key('UcMaterial',concat(generate-id(../../..),'+',Material,'+',Color,'+',DimCut3,'+',DimCut2,'+',DimCut1,'+',Comment,'+',Edging,'+',Quantity))" />
                                        <xsl:for-each select="../Component[generate-id()=generate-id(key('UcMaterial',concat(generate-id(../../..),'+',Material,'+',Color,'+',DimCut3,'+',DimCut2,'+',DimCut1,'+',Comment,'+',Edging,'+',Quantity))[1])]">
                                            <fo:table-row>
                                                <!-- 1 --><fo:table-cell><fo:block><xsl:value-of select="Comment" /></fo:block></fo:table-cell>
                                                <!-- 2 --><fo:table-cell><fo:block><xsl:value-of select="sum($similar/Quantity)" />@</fo:block></fo:table-cell>
                                                <!-- 3 --><fo:table-cell><fo:block><xsl:value-of select="DimCut1" /></fo:block></fo:table-cell>
                                                <!-- 4 --><fo:table-cell><fo:block><xsl:value-of select="DimCut2" /></fo:block></fo:table-cell>
                                                <!-- 5 --><fo:table-cell><fo:block></fo:block></fo:table-cell>
                                                <!-- 6 --><fo:table-cell><fo:block></fo:block></fo:table-cell>
                                            </fo:table-row>
                                        </xsl:for-each>
                                    </xsl:for-each>
                            </xsl:for-each>

现在我们可以按预期循环并避免由于 Xalan 处理器导致的重复错误。