使用XSL-FO表进行Muenchian分组 [英] Muenchian Grouping with XSL-FO Table

查看:77
本文介绍了使用XSL-FO表进行Muenchian分组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在使用RenderX XEP中的XSL-FO生成简单的PDF,但是对于XPath涉及更多的功能,我还是比较陌生.

I've been working with producing simple PDFs with XSL-FO in RenderX XEP for a while, but I'm relatively new to the more involved functions of XPath.

我有一些看起来像这样的XML:

I have some XML which looks like this:

<?xml version="1.0" encoding="UTF-8"?>
<report>
    <ticket>
        <size>A</size>
        <department>Dept 1</department>
        <category>Cat 1</category>
        <product>Product 1</product>
    </ticket>
    <ticket>
        <size>A</size>
        <department>Dept 1</department>
        <category>Cat 2</category>
        <product>Product 2</product>
    </ticket>
    <ticket>
        <size>B</size>
        <department>Dept 1</department>
        <category>Cat 2</category>
        <product>Product 3</product>
    </ticket>
    <ticket>
        <size>B</size>
        <department>Dept 1</department>
        <category>Cat 1</category>
        <product>Product 1</product>
    </ticket>
    <ticket>
        <size>C</size>
        <department>Dept 1</department>
        <category>Cat 2</category>
        <product>Product 2</product>
    </ticket>
    <ticket>
        <size>D</size>
        <department>Dept 3</department>
        <category>Cat 1</category>
        <product>Product 4</product>
    </ticket>
    <ticket>
        <size>D</size>
        <department>Dept 1</department>
        <category>Cat 1</category>
        <product>Product 1</product>
    </ticket>
</report>

我需要能够使用XSLT1.0格式设置对象将数据分类为PDF表格.所需的格式如下:

I need to be able to sort this data into tables into a PDF using XSLT1.0 formatting objects. The desired format being the following:

相同大小的所有票证都位于单独的表中(在页面中按字母顺序排序),每个表都列出了其产品,包含在其相关类别和部门中. 示例:

All tickets of the same size being in separate tables (sorted on the page in alphabetical order), which each list their products, contained within their relevant categories and departments. Example:

我曾经实现过Muenchian分组,但是使用大型XML提取时,错误的类别属于部门,而且我无法在每个类别下列出相关产品.

I have had a go at implementing Muenchian grouping, but the wrong categories are falling under the departments when using a large XML extract, and I haven't been able to list the relevant products below each category.

我可能不太整洁的XSL:

My probably rather untidy XSL:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format">

    <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>

    <xsl:key name="keySize" match="ticket" use="size" />
    <xsl:key name="keyDepartment" match="ticket" use="concat(size, ' ', department)" />
    <xsl:key name="keyCategory" match="ticket" use="concat(size, ' ', department, ' ', category)" />

    <xsl:template match="/report">
        <fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">
            <fo:layout-master-set>
                <fo:simple-page-master master-name="simple" page-height="29.7cm" page-width="21cm" margin-top="2cm" margin-bottom="2cm" margin-left="2cm" margin-right="2cm">
                    <fo:region-body />
                </fo:simple-page-master>
            </fo:layout-master-set>
            <fo:page-sequence master-reference="simple">
                <fo:flow flow-name="xsl-region-body">

                    <xsl:for-each select="ticket[count(. | key('keySize', size)[1]) = 1]">
                        <xsl:sort select="size" order="ascending" />
                        <fo:block>
                            Size <xsl:value-of select="size" />
                        </fo:block>
                        <fo:block>
                            <xsl:variable name="sizes" select="key('keySize', size)" />
                            <xsl:for-each select="$sizes[generate-id() = generate-id(key('keyDepartment', concat(size, ' ', department))[1])]">
                                <xsl:sort select="department" order="ascending" />

                                <!--TABLES START-->
                                <fo:table-and-caption>
                                    <fo:table border="0.2mm solid black" width="100%">
                                        <fo:table-header>
                                            <fo:table-row>
                                                <fo:table-cell>
                                                    <fo:block font-weight="bold" margin="1mm 0mm 0mm 1mm">
                                                        <xsl:text>Department</xsl:text>
                                                    </fo:block>
                                                </fo:table-cell>
                                                <fo:table-cell>
                                                    <fo:block font-weight="bold" margin="1mm 0mm 0mm 1mm">
                                                        <xsl:value-of select="department" />
                                                    </fo:block>
                                                </fo:table-cell>
                                            </fo:table-row>
                                        </fo:table-header>
                                        <fo:table-body>
                                            <fo:table-cell>
                                                <fo:block margin="1mm 0mm 0mm 1mm" />
                                            </fo:table-cell>
                                        </fo:table-body>
                                    </fo:table>
                                </fo:table-and-caption>

                                <!--BRINGS IN WRONG CATEGORIES-->
                                <xsl:for-each select="$sizes[generate-id() = generate-id(key('keyCategory', concat(size, ' ', department, ' ', category))[1])]">
                                    <xsl:sort select="category" order="ascending" />
                                    <fo:table-and-caption>
                                        <fo:table border="0.2mm solid black" width="100%">
                                            <fo:table-header>
                                                <fo:table-row>
                                                    <fo:table-cell>
                                                        <fo:block font-weight="bold" margin="1mm 0mm 0mm 1mm">
                                                            <xsl:text>Category</xsl:text>
                                                        </fo:block>
                                                    </fo:table-cell>
                                                    <fo:table-cell>
                                                        <fo:block font-weight="bold" margin="1mm 0mm 0mm 1mm">
                                                            <xsl:value-of select="category" />
                                                        </fo:block>
                                                    </fo:table-cell>
                                                </fo:table-row>
                                            </fo:table-header>
                                            <fo:table-body>
                                                <fo:table-row>
                                                    <fo:table-cell>
                                                        <fo:block margin="1mm 0mm 0mm 1mm"><xsl:value-of select="description" /></fo:block>
                                                    </fo:table-cell>
                                                </fo:table-row>

                                                <!--

                                                DESCRIPTIONS GO HERE?

                                                -->
                                            </fo:table-body>
                                        </fo:table>
                                    </fo:table-and-caption>
                                </xsl:for-each>                         
                            </xsl:for-each>                         
                        </fo:block>
                    </xsl:for-each>
                </fo:flow>
            </fo:page-sequence>
        </fo:root>
    </xsl:template>
</xsl:stylesheet>

在提供产品方面的任何帮助将不胜感激.

Any help with bringing in the products would be greatly appreciated.

推荐答案

我认为问题出在这行上,在这里您尝试遍历部门的所有类别

I think the problem is with this line, where you try to iterate over all categories for a department

<xsl:for-each select="$sizes[generate-id() = generate-id(key('keyCategory', concat(size, ' ', department, ' ', category))[1])]">

问题在于变量 sizes 包含有关不同部门的详细信息,而不仅仅是您感兴趣的部门,导致重复.

The problem is the variable sizes contains details on different departments, not just the one you are interested in, leading to duplicates.

改为尝试此操作,以将其限制为当前部门

Try this instead, to restrict it to the current department

<xsl:variable name="depts" select="key('keyDepartment', concat(size, ' ', department))" />
<xsl:for-each select="$depts[generate-id() = generate-id(key('keyCategory', concat(size, ' ', department, ' ', category))[1])]">

这篇关于使用XSL-FO表进行Muenchian分组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆