问题标签 [muenchian-grouping]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
2 回答
799 浏览

xml - XSLT - 从一组相同的节点中打印第一个节点

我在尝试仅为一组相同的节点打印一行时遇到问题,但我找不到相同节点的类似帖子。

我有一个包含一组相同节点的输入 xml 文件,例如它看起来像:

我想要的是只打印一次这本书的信息。我认为我的问题的解决方案可能是 muenchian 分组,例如按 ISBN 值分组,然后从组中仅打印第一个。

基于此,我的代码如下所示:

和:

如果我的输入 xml 文件仅包含一个 BK 元素,则代码可以正常工作。如果我有多个如上所示,Apache FOP 会返回一个与表格单元格相关的错误:“行中的列号或单元格数溢出为表格指定的 fo:table-columns 的数量。”

该错误表明我正在尝试在我的表格行中放置更多表格单元格,而:a)我希望此示例仅打印 1 行 b)在更多 ISBN 的情况下生成更多行,而不是更多表格单元格.

任何帮助将不胜感激,谢谢!

0 投票
1 回答
37 浏览

xml - Grouping elements by attribute of multiple identical childs in xslt 1.0

I've got an XML that looks like this:

And I need to create a xslt that groups the "itinerary" nodes that share the flight numbers of their flight segments.

Eventually, i need the following html output:

But for now, i've got as far as:

But something must be wrong with my key, because i get a null result, just the first empty table, but the debugger does not show any compilation error or problem with my code.

I've been looking for differents methods of muenchian grouping and compound keys, but i can't find a solution. I don't even know why my key does not work, so any help you could give me would be greatly apreciated.

Thanks in advance.

0 投票
2 回答
1248 浏览

xml - 多个键上的 XSLT 组

这是输入文件。

输出是:

分组规则

  • 价格
  • 腿组=0 和组=1 是对。当leg Group=0 具有相同的Key=in Group=1 时,我们可以对leg 进行分组。例如,Group=0 中的 Leg 具有 Key=56T58T 和 Group=1 中的两个 Key(177T179T 和 196T198T)。相同的两个 Key(177T179T 和 196T198T)的 Leg in Group=0 Key=128T130T。所以我们可以对其进行分组

    我正在使用 XSLT 1.0。任何帮助将不胜感激。



    我有 xsl,但它只按价格分组

    和输出:

    任何帮助将不胜感激。

    逐步分组。

    1. Leg Group=0 按相同的价格和相同的键分组

      <Group Price="541"> <Leg Key="56T58T" Group="0"></Leg> <Leg Key="177T179T" Group="1"></Leg> <Leg Key="56T58T" Group="0"></Leg> <Leg Key="196T198T" Group="1"></Leg> </Group> <Group Price="541"> <Leg Key="128T130T" Group="0"></Leg> <Leg Key="196T198T" Group="1"></Leg> <Leg Key="128T130T" Group="0"></Leg> <Leg Key="177T179T" Group="1"></Leg> </Group> <Group Price="541"> <Leg Key="243T246T" Group="0"></Leg> <Leg Key="60T63T" Group="1"></Leg> <Leg Key="243T246T" Group="0"></Leg> <Leg Key="133T136T" Group="1"></Leg> </Group> <Group Price="700"> <Leg Key="243T" Group="0"></Leg> <Leg Key="133T136T" Group="1"></Leg> </Group>

    2. 在每个组中删除重复的腿(相同的键)

      <Group Price="541" > <Leg Key="56T58T" Group="0"></Leg> <Leg Key="177T179T" Group="1"></Leg> <Leg Key="196T198T" Group="1"></Leg> </Group> <Group Price="541"> <Leg Key="128T130T" Group="0"></Leg> <Leg Key="196T198T" Group="1"></Leg> <Leg Key="177T179T" Group="1"></Leg> </Group> <Group Price="541"> <Leg Key="243T246T" Group="0"></Leg> <Leg Key="60T63T" Group="1"></Leg> <Leg Key="133T136T" Group="1"></Leg> </Group> <Group Price="700"> <Leg Key="243T" Group="0"></Leg> <Leg Key="133T136T" Group="1"></Leg> </Group>

    3. 为 Leg Group=1 分组相同的价格和相同的键(第一个和第二个组具有相同的 Legs Group=1,所以我们可以使用 Gruop )

      <Group Price="541"> <Leg Key="56T58T" Group="0"></Leg> <Leg Key="177T179T" Group="1"></Leg> <Leg Key="196T198T" Group="1"></Leg> <Leg Key="128T130T" Group="0"></Leg> <Leg Key="196T198T" Group="1"></Leg> <Leg Key="177T179T" Group="1"></Leg> </Group> <Group Price="541"> <Leg Key="243T246T" Group="0"></Leg> <Leg Key="60T63T" Group="1"></Leg> <Leg Key="133T136T" Group="1"></Leg> </Group> <Group Price="700"> <Leg Key="243T" Group="0"></Leg> <Leg Key="133T136T" Group="1"></Leg> </Group>

    4. 在每个组中删除重复的腿(相同的键)

      <Group Price="541"> <Leg Key="56T58T" Group="0"></Leg> <Leg Key="128T130T" Group="0"></Leg> <Leg Key="177T179T" Group="1"></Leg> <Leg Key="196T198T" Group="1"></Leg> </Group> <Group Price="541"> <Leg Key="243T246T" Group="0"></Leg> <Leg Key="60T63T" Group="1"></Leg> <Leg Key="133T136T" Group="1"></Leg> </Group> <Group Price="700"> <Leg Key="243T" Group="0"></Leg> <Leg Key="133T136T" Group="1"></Leg> </Group>

    最后它的输出。

  • 0 投票
    1 回答
    976 浏览

    xml - XSLT 键,嵌套或多个

    这是我的 xml(大大简化和缩短,在我的真实交易中有 100 多个“电影”元素)

    我已经从这个例子中删除了除了标题和类型之外的所有内容,因为那是让我绊倒的部分。我正在尝试将它们转换为可用作可导航工具栏的良好格式

    像这样的东西:

    等等等等。每个“流派”都有一个<li>,并且它的所有子流派都被放置<ul>在它下面的一个新的,如果有一个子子流派(就像 Kon-Tiki 一样)它只是扩展了一个级别。

    我一直在阅读关于钥匙和 Muenchian Grouping 的文章——

    我的 XSL 文件顶部有这个键

    并了解它按我给它们的名称索引过流派元素,然后使用

    在一个<xsl:for-each><xsl:apply-templates>我可以做任何我想做的每一个流派。这工作正常。

    它让子流派出现在每一个杀死我的地方。

    我有这个,这是错误的,但我不知道如何使它正确。

    如果您能解释它是如何工作的,我很乐意接受 xsl 2.0 解决方案!但我对 1.0 有更坚定的把握。

    0 投票
    1 回答
    330 浏览

    xml - 如何使用 Muenchian 方法在 XSLT 中进行分组?

    我对 XSLT 很陌生,我正在使用 XSLT 1.0。现在我需要将一些东西分组到一个相当大的 XML 文件中。那里有很多例子,但出于某种原因,没有一个对我有用。我可以对我想要的信息进行分组,但我的输出 xml 中也有一些额外的文本。这就是我现在正在做的事情;

    输入 XML(这是一个临时 XML,实际输入要大得多,但我也可以将其应用于我的真实 xml)

    现在我想按项目编号对项目进行分组。这就是我所做的;

    有了这段代码,我得到了这个输出;

    这几乎正​​是我想要的,除了“15”。我从根目录下的标签中得到分组的数字和一个值。

    当我尝试将此 XSLT 应用于我的主要 XML 时,我遇到了完全相同的错误,我从根目录下的标签和其他一些标签中得到了我想要的大量不需要的信息。这里有什么问题?

    我猜这与模板或匹配有关,但我真的不知道如何解决。

    非常感谢。

    0 投票
    1 回答
    207 浏览

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

    一段时间以来,我一直在使用 RenderX XEP 中的 XSL-FO 制作简单的 PDF,但我对 XPath 涉及的更多功能相对较新。

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

    我需要能够使用 XSLT1.0 格式化对象将这些数据排序到 PDF 中。所需的格式如下:

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

    期望的输出

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

    我可能相当凌乱的 XSL:

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

    0 投票
    1 回答
    121 浏览

    xslt - 使用 XSLT 1.0 Muenchian Grouping 创建 HTML 输出时排序失败

    我有以下 XML:

    在下面的 XSLT 中,我尝试使用 Muenchian 分组按类别名称(升序)和在每个类别中按测试用例名称(升序)排序。

    但是,我得到的是:

    每个类别的测试用例数量是正确的,但没有应用排序,并且始终使用第一个测试用例名称。我怎样才能解决这个问题?

    0 投票
    2 回答
    182 浏览

    xslt - More XSL Grouping - how to remove parent nodes with duplicate child attributes?

    Yes, this is another XSLT grouping/duplicates questions, but I was unable to find any answers that I could successfully apply to my situation.

    This is the original XML:

    First, I need it grouped by attribute "groupNum" and wrapped in a parent element jsxid that increments with each group, so that the output looks like this:

    I was able to accomplish that with this stylesheet:

    Now I need to remove any grouping that contains the exact same items as another grouping for records where total = "1". If you look at the groupings of jsxid = 2 and jsxid = 3 above, you'll see that they both contain the following item attributes, though not in the same order:

    So I want to remove the entire jsxid = 3 grouping and have the final output look like this:


    EDIT: Instead of removing the duplicate grouping, what if I wanted to add in a new attribute as a "grouping identifier." I'd call it something like "groupType" so the output for the above situation where the last two groupings are the same, they would have the same grouptype:


    Any help is greatly appreciated.

    0 投票
    1 回答
    2412 浏览

    xml - XSLT 1.0:按属性分组

    我有以下简化的 XML 数据,我想按类别对其进行分组:

    我希望得到以下结果:

    第一类

    • 文件 1
    • 文件 3

    第 2 类

    • 文件 2
    • 文件 4

    第 3 类

    • 文件 5

    我已经尝试过使用 Muenchian 分组,因为我只能使用 XSLT 1.0 ,但是没有输出:

    我没有找到按名称是另一个属性的属性进行分组的解决方案。我的错在哪里,还是有更好的解决方案?提前致谢

    0 投票
    2 回答
    398 浏览

    sorting - Xslt 嵌套排序

    我正在尝试按字母顺序对字段进行排序(在本例中为 VICINITY),但如果不存在(VICINITY),我需要考虑另一个字段(ITA_LIGHT_NAME),从而创建两个嵌套排序。

    我创建了这个 xslt:

    这给出了两个结果(列表 A 和列表 B 分为两个不同的列表):

    但是,我真的很想作为最终输出一个列表(按字母顺序排序):

    实际上,应该按以下方式工作:如果存在,则按 VICINITY 的字母顺序(不重复),如果不存在,则按 ITA_LIGHT_NAME 的顺序(不重复)。

    这是我的 XML,你能帮忙模拟一下这个输出吗: