gpt4 book ai didi

xml - 使用XSL-FO表进行Muenchian分组

转载 作者:行者123 更新时间:2023-12-03 16:54:07 24 4
gpt4 key购买 nike

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

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

<?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表格。所需的格式如下:

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



我可以实施Muenchian分组,但是使用大的XML提取时,错误的类别属于部门,并且我无法在每个类别下列出相关产品。

我可能不太整洁的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>


任何有关引入产品的帮助将不胜感激。

最佳答案

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

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


问题在于变量大小包含不同部门的详细信息,而不仅仅是您感兴趣的部门的详细信息,从而导致重复。

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

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

关于xml - 使用XSL-FO表进行Muenchian分组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24411173/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com