0

(Using XSLT 1.0 and running through FOP 1.1) Cut down 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>

Below is the shortened XSL:FO that will produce the unexpected duplication.

    <?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>

My Expected result is to see the following sort of table form...

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

But What I am seeing is:

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

The problem is why is it duplicating the task, I cannot seem to get my head around the <for-each> loops are picking up more than I am expecting.

(the original method of this tranformation came from this question, XSL Grouping nodes by multiple similar siblings with multiple similar unknown values)

Community
  • 1
  • 1
  • 1
    Can you please post a minimal code to represent the same problem. – Lingamurthy CS Aug 11 '16 at 00:10
  • Thats as small as I can get it. If I could trim it further I might be able to solve my issue, which I still am trying to do on my side. – Alistair Lindsay-Macfadyen Aug 11 '16 at 00:40
  • The XSLT that you provide doesn't produce either result that you provide. I don't get the duplication, and I don't get all of your text. Should `Comment` be `Component`? – Tony Graham Aug 11 '16 at 07:23
  • What XSLT processor are you using and how are you running it? – Michael Kay Aug 11 '16 at 07:26
  • I am running it through FOP 1.1 – Alistair Lindsay-Macfadyen Aug 11 '16 at 08:54
  • Sorry saw Component was meant to be comment in xml, corrected. – Alistair Lindsay-Macfadyen Aug 11 '16 at 08:58
  • Michael Kay's question was about your XSLT processor, not your XSL formatter. Your XSLT stylesheet could be made simpler if you are using XSLT 2.0, but in your linked question, you say you are using XSLT 1.0. – Tony Graham Aug 11 '16 at 10:20
  • Sorry about that, yes XSLT 1.0 – Alistair Lindsay-Macfadyen Aug 11 '16 at 10:28
  • Have you run your own sample? Corrected XML had two typos that made it not well-formed, and the output still doesn't repeat the way that you say it does. – Tony Graham Aug 11 '16 at 11:17
  • I will re-run my sample tomorrow morning. And edit where required. – Alistair Lindsay-Macfadyen Aug 11 '16 at 11:19
  • Ok I finally managed to reduce this down to a working smaller sample with the problem still occuring, the XML is updated and the XSL is also update with what I am running to still trigger the results. – Alistair Lindsay-Macfadyen Aug 12 '16 at 05:39
  • Please post a minimal, but complete stylesheet - one we can copy and run *as is*. – michael.hor257k Aug 12 '16 at 06:06
  • @michael.hor257k Edited as requested and tested on my side that it is still producing the same result I am expecting. It seems to be somewhere in my for-each but I am not good with xsl:key so I am not exactly sure how to manipulate it properly. – Alistair Lindsay-Macfadyen Aug 12 '16 at 06:26
  • I ran the XSL transformation and I see no duplicates in the resulting XML document. I then converted that XML to PDF using http://www.utilities-online.info/foprender/?save=1ffab590-de91-4253-9eff-9f143b7bad21-foprender and - as you can see yourself - the problem cannot be reproduced. -- I have not checked your actual code. – michael.hor257k Aug 12 '16 at 06:49
  • hmm I can see two results there @michael.hor257k, firstly I dumped a copy of the XML on the left window, then dumped a copy of my XSL on the left window and below that above the third bottom/middle window i hit "transform to FO and generate PDF" and I got my usual duplicate result. however underneath when i used the "Check XSL-FO validity" it said well formed and then used the "transform to PDF" then I saw the CORRECT output with no duplicates... – Alistair Lindsay-Macfadyen Aug 12 '16 at 06:55
  • And tried again in a different combo and still get the duplicates. Pasted in the XML and it is valid, then Pasted in the XSL and checked it was valid, then told it to Transform and insert FO below, then generated the PDF off the last dialog box and it did the duplicates again.. – Alistair Lindsay-Macfadyen Aug 12 '16 at 07:01
  • This seems to be a Xalan issue. I have now replicated the problem (earlier I used another XSLT processor). Let me see if I can pin it down. – michael.hor257k Aug 12 '16 at 07:04
  • @michael.hor257k thanks, I would be completely out of my depth to work out the problem if it is down in that area. – Alistair Lindsay-Macfadyen Aug 12 '16 at 07:07

2 Answers2

2

This seems to be a bug in the Xalan processor. It is triggered by the

<xsl:sort select="Comment" />

instruction on line #86. If you remove it, the duplicates will go away.

I should add that I did not try to understand your code, but it seems to me it could be simplified significantly. Perhaps that too could prevent the bug from manifesting itself.

michael.hor257k
  • 113,275
  • 6
  • 33
  • 51
  • Ok I can remove the sort but I really did need to do that to put the parts into an order. I am not tied to using the way I have if there was an alternative. – Alistair Lindsay-Macfadyen Aug 12 '16 at 08:08
  • Removed the Sort and you are correct the results are as desired except I want to be able to sort the pieces into order alphabetically by comment name – Alistair Lindsay-Macfadyen Aug 12 '16 at 08:13
  • I cannot provide an alternative, because I don't know the purpose. Do you really need to nest that many tables? Anyway, that would be a topic for another question. And I would suggest you start by solving the problem for a simple HTML table, before moving to XSL-FO. – michael.hor257k Aug 12 '16 at 08:14
  • Thanks for your help on that, greatly appreciated. with regards to the tables, not sure, experience probably, I might look into the fo:block a bit more and see what I can do with that, I needed the nested tables to position the data around the page in a tabular manner, I'm going direct to PDF so laying out in HTML will not help me here as they format differently. – Alistair Lindsay-Macfadyen Aug 15 '16 at 02:42
0

A work around has been given to me from an internal source, and it still doesn't change the fact that the answer from @Micahael.hor257k is correct.

if we use;

<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)" />

Then what we need to do is use another key() of the first one to use inside the loop to prevent the duplication occuring, like so.

<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)" />

now in the XSL we can change the code slightly to read the below snip;

<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>

Now we can loop through as expected and avoid the duplication error due to the Xalan Processor.