使用xslt样式表导出时如何实现xml分组(对于Excel)

时间:2016-06-01 16:04:50

标签: xml xslt-1.0 filemaker

我正在尝试使用Filemaker 14中的导出记录功能创建格式化的Excel文件。

该文件保存为要在Excel中打开的“.xls”文件,但导出格式为XML,我使用xslt样式表进行一些样式设置。

到目前为止,填充工作正在进行,但我仍然试图实施分组。

修改 这是基于michael链接的WORKING xslt(如果有人发现它有用):

   <?xml version="1.0" encoding="UTF-8" ?>
    <xsl:stylesheet
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:fmp="http://www.filemaker.com/fmpxmlresult" version="1.0"
    exclude-result-prefixes="fmp set"
    xmlns:set="http://exslt.org/sets"
    xmlns="urn:schemas-microsoft-com:office:spreadsheet"
    xmlns:o="urn:schemas-microsoft-com:office:office"
    xmlns:x="urn:schemas-microsoft-com:office:excel"
    xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet"
    xmlns:html="http://www.w3.org/TR/REC-html40">
    <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>

    <xsl:key name="group" match="fmp:ROW" use="fmp:COL[8]/fmp:DATA" />

    <xsl:template match="fmp:FMPXMLRESULT">
        <Workbook
            xmlns="urn:schemas-microsoft-com:office:spreadsheet"
            xmlns:o="urn:schemas-microsoft-com:office:office"
            xmlns:x="urn:schemas-microsoft-com:office:excel"
            xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet"
            xmlns:html="http://www.w3.org/TR/REC-html40">
            <DocumentProperties xmlns="urn:schemas-microsoft-com:office:office">
                <LastAuthor/>
                <Created/>
                <Version>11.9999</Version>
            </DocumentProperties>
            <ExcelWorkbook xmlns="urn:schemas-microsoft-com:office:excel">
                <WindowHeight>8190</WindowHeight>
                <WindowWidth>16380</WindowWidth>
                <WindowTopX>0</WindowTopX>
                <WindowTopY>0</WindowTopY>
                <TabRatio>505</TabRatio>
                <ProtectStructure>False</ProtectStructure>
                <ProtectWindows>False</ProtectWindows>
            </ExcelWorkbook>
            <Styles>
                <Style ss:ID="Default" ss:Name="Normal">
                    <Alignment ss:Vertical="Bottom"/>
                    <Borders/>
                    <Font x:Family="Swiss"/>
                    <Interior/>
                    <NumberFormat/>
                    <Protection/>
                </Style>
                <Style ss:ID="Header">
                    <Alignment ss:Horizontal="Center" ss:Vertical="Center" ss:WrapText="0"/>
                    <Borders/>
                    <Interior ss:Color="#222D33" ss:Pattern="Solid"/>
                    <Font ss:Color="#FFFFFF" ss:Size="30" ss:FontName="Verdana" x:Family="Swiss" ss:Bold="1" ss:Underline="Single"/>
                </Style>
                <Style ss:ID="ColNames">
                    <Alignment ss:Horizontal="Center" ss:Vertical="Center" ss:WrapText="1"/>
                    <Font ss:Color="#FFFFFF" ss:FontName="Verdana" x:Family="Swiss" ss:Bold="1"/>
                    <Interior ss:Color="#839997" ss:Pattern="Solid"/>
                </Style>
                <Style ss:ID="Data">
                    <Alignment ss:Horizontal="Center" ss:Vertical="Bottom" ss:WrapText="1"/>
                    <Borders />
                    <Font ss:Color="#090A0E" ss:FontName="Verdana" x:Family="Swiss"/>
                    <Interior ss:Color="#D8E2E1" />
                </Style>
                <Style ss:ID="Group">
                    <Alignment ss:Horizontal="Left" ss:Vertical="Center" ss:WrapText="0"/>
                    <Borders />
                    <Font ss:Size="18" ss:Color="#090A0E" ss:FontName="Verdana" x:Family="Swiss" ss:Bold="1" ss:Underline="Single"/>
                    <Interior ss:Color="#000000" />
                </Style>
            </Styles>
            <Worksheet ss:Name="Sheet1">
                <Table ss:ExpandedColumnCount="7" x:FullColumns="1" x:FullRows="1" >
                    <xsl:attribute name="ss:ExpandedRowCount"><xsl:value-of select="count(fmp:RESULTSET/fmp:ROW)+10"/>
                    </xsl:attribute>
                    <Column ss:AutoFitWidth="0" ss:Width="150"/>
                    <Column ss:AutoFitWidth="0" ss:Width="250"/>
                    <Column ss:AutoFitWidth="0" ss:Width="150"/>
                    <Column ss:AutoFitWidth="0" ss:Width="150"/>
                    <Column ss:AutoFitWidth="0" ss:Width="100"/>
                    <Column ss:AutoFitWidth="0" ss:Width="100"/>
                    <Column ss:AutoFitWidth="0" ss:Width="100"/>
                    <Row ss:AutoFitHeight="0" ss:Height="100">
                        <Cell ss:StyleID="Header">
                        </Cell>
                        <Cell ss:StyleID="Header">
                        </Cell>
                        <Cell ss:StyleID="Header">
                            <Data ss:Type="String">Suppler Items</Data>
                        </Cell>
                        <Cell ss:StyleID="Header">
                        </Cell>
                        <Cell ss:StyleID="Header">
                        </Cell>
                        <Cell ss:StyleID="Header">
                        </Cell>
                        <Cell ss:StyleID="Header">
                        </Cell>
                    </Row>
                    <Row ss:AutoFitHeight="0" ss:Height="24" >
                        <Cell ss:StyleID="ColNames">
                            <Data ss:Type="String">CODE</Data>
                        </Cell>
                        <Cell ss:StyleID="ColNames">
                            <Data ss:Type="String">DESCRIPTION</Data>
                        </Cell>
                        <Cell ss:StyleID="ColNames">
                            <Data ss:Type="String">BARCODE</Data>
                        </Cell>
                        <Cell ss:StyleID="ColNames">
                            <Data ss:Type="String">COST</Data>
                        </Cell>
                        <Cell ss:StyleID="ColNames">
                            <Data ss:Type="String">UOM</Data>
                        </Cell>
                        <Cell ss:StyleID="ColNames">
                            <Data ss:Type="String">SIZE</Data>
                        </Cell>
                        <Cell ss:StyleID="ColNames">
                            <Data ss:Type="String">VAT</Data>
                        </Cell>
                    </Row>

                    <xsl:for-each select="set:distinct(fmp:RESULTSET/fmp:ROW/fmp:COL[8]/fmp:DATA)">
                        <Row ss:AutoFitHeight="0" ss:Height="30" >
                            <Cell ss:StyleID="Group">
                                <Data ss:Type="String">
                                    <xsl:value-of select="../../fmp:COL[8]/fmp:DATA"/>
                                </Data>

                            </Cell>
                        </Row>
                        <xsl:for-each select="key('group', .)">
                            <xsl:variable name="code" select="fmp:COL[1]/fmp:DATA"/>
                            <xsl:variable name="name" select="fmp:COL[2]/fmp:DATA"/>
                            <xsl:variable name="barcode" select="fmp:COL[3]/fmp:DATA"/>
                            <xsl:variable name="cost" select="fmp:COL[4]/fmp:DATA"/>
                            <xsl:variable name="uom" select="fmp:COL[5]/fmp:DATA"/>
                            <xsl:variable name="size" select="fmp:COL[6]/fmp:DATA"/>
                            <xsl:variable name="VAT" select="fmp:COL[7]/fmp:DATA"/>

                            <Row ss:AutoFitHeight="0" ss:Height="20">
                                <Cell ss:StyleID="Data">
                                    <Data ss:Type="String">
                                        <xsl:value-of select="$code"/>
                                    </Data>
                                </Cell>
                                <Cell ss:StyleID="Data">
                                    <Data ss:Type="String">
                                        <xsl:value-of select="$name"/>
                                    </Data>
                                </Cell>
                                <Cell ss:StyleID="Data">
                                    <ss:Data ss:Type="String" >
                                        <xsl:value-of select="$barcode"/>
                                    </ss:Data>
                                </Cell>
                                <Cell ss:StyleID="Data">
                                    <Data ss:Type="String">
                                        <xsl:value-of select="$cost"/>
                                    </Data>
                                </Cell>
                                <Cell ss:StyleID="Data">
                                    <Data ss:Type="String">
                                        <xsl:value-of select="$uom"/>
                                    </Data>
                                </Cell>
                                <Cell ss:StyleID="Data">
                                    <Data ss:Type="String">
                                        <xsl:value-of select="$size"/>
                                    </Data>
                                </Cell>
                                <Cell ss:StyleID="Data">
                                    <Data ss:Type="String">
                                        <xsl:value-of select="$VAT"/>
                                    </Data>
                                </Cell>
                            </Row>
                        </xsl:for-each>
                    </xsl:for-each>
                </Table>
                <WorksheetOptions xmlns="urn:schemas-microsoft-com:office:excel">
                    <PageSetup>
                        <Layout x:Orientation="Landscape"/>
                        <Header x:Margin="0.1701388888888889"/>
                        <Footer x:Margin="0.15972222222222221" x:Data=" "/>
                        <PageMargins x:Bottom="0.16944444444444443" x:Left="0.2" x:Right="0.19027777777777777" x:Top="0.4604166666666667"/>
                    </PageSetup>
                    <FitToPage/>
                    <Print>
                        <FitHeight>0</FitHeight>
                        <ValidPrinterInfo/>
                        <PaperSizeIndex>9</PaperSizeIndex>
                        <HorizontalResolution>300</HorizontalResolution>
                        <VerticalResolution>300</VerticalResolution>
                    </Print>
                    <Zoom>85</Zoom>
                    <Selected/>
                    <Panes>
                        <Pane>
                            <Number>3</Number>
                            <ActiveRow>1</ActiveRow>
                            <ActiveCol>1</ActiveCol>
                        </Pane>
                    </Panes>
                    <ProtectObjects>False</ProtectObjects>
                    <ProtectScenarios>False</ProtectScenarios>
                </WorksheetOptions>
            </Worksheet>
        </Workbook>
    </xsl:template>

</xsl:stylesheet>

这是迄今为止的结果: enter image description here

非常感谢任何朝着正确方向的轻推/推/推!

0 个答案:

没有答案