xsl:for-each循环是复制我不期望的东西

时间:2016-08-11 00:08:21

标签: xml xslt xsl-fo

(使用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>$0.00</UnitCost>
                    <Cost>$0.00</Cost>
                    <UnitSell>$0.00</UnitSell>
                    <Sell>$0.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>$0.00</UnitCost>
                    <Cost>$0.00</Cost>
                    <UnitSell>$0.00</UnitSell>
                    <Sell>$0.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>$0.00</UnitCost>
                    <Cost>$0.00</Cost>
                    <UnitSell>$0.00</UnitSell>
                    <Sell>$0.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>$0.00</UnitCost>
                    <Cost>$0.00</Cost>
                    <UnitSell>$0.00</UnitSell>
                    <Sell>$0.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>$0.00</UnitCost>
                    <Cost>$0.00</Cost>
                    <UnitSell>$0.00</UnitSell>
                    <Sell>$0.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>$0.00</UnitCost>
                    <Cost>$0.00</Cost>
                    <UnitSell>$0.00</UnitSell>
                    <Sell>$0.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>$0.00</UnitCost>
                    <Cost>$0.00</Cost>
                    <UnitSell>$0.00</UnitSell>
                    <Sell>$0.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>$0.00</UnitCost>
                    <Cost>$0.00</Cost>
                    <UnitSell>$0.00</UnitSell>
                    <Sell>$0.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>

我的预期结果是看到以下类型的表格形式......

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>循环比我预期的要多。

(这种转变的原始方法来自这个问题,XSL Grouping nodes by multiple similar siblings with multiple similar unknown values

2 个答案:

答案 0 :(得分:2)

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

触发
<xsl:sort select="Comment" />
#p>第86行的说明。如果删除它,副本将会消失。

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

答案 1 :(得分:0)

从内部来源给我一个解决方法,它仍然没有改变@ 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)" />

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

<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 Processor导致的重复错误。