问题标签 [xslt-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 投票
1 回答
4688 浏览

xml - 一次在 XSLT 中输出多个表

我有一个 XML 文档:

我想要做的是用 XSL 制作 3 个表,标题是子元素的名称(仅一次),子标题是孙元素的名称(仅一次),其余的行和列将填充值的孙子元素。

据我所知:

这是输出:

输出
(来源:UploadScreenshot.com

发生的事情是,每次为每个子元素创建一个新表时,但我想要的是一个智能代码,它将自动生成所有 3 个表,然后生成标题和子标题,然后输入数据. 我想要的是这样的(忽略颜色和文本格式):

输出

我希望我的 XSLT 代码为每个元素实例创建一个表,然后将元素的名称作为标题,然后将子元素作为标题一次,然后用数据填充表。

0 投票
2 回答
21354 浏览

xml - XSLT 排序 - 如何使用属性对父节点内的 xml 子节点进行排序

开始是一件简单的事情,但对于 XSLT 菜鸟来说却相当麻烦。

尝试对子节点/降序进行排序,但是在向其父节点添加属性后,在 VS2010 中调试时收到错误消息:

"Attribute and namespace nodes cannot be added to the parent element after a text, comment, pi, or sub-element node has already been added."

假设我有这个简单的 XML:

我将 XPATH 传递给 xmldatasource 以检索相关<year>节点,例如 2013。然后我需要<post>使用 postid 对其子节点进行降序排序,因此对于<year value=2013>, postid=10050 将在呈现时首先显示。

所以,要明确一点:我只对在一个<year>节点内进行排序感兴趣。

在我将节点拆分为单独的节点(即 xml 是 /posts/post)之前,以下 XSLT 工作:

由于上述错误,现在运行时 xmldatasource 为空。如果我按升序传递,则明显返回相同的 xml(无转换)

问题:如何更新上述(或新的)XSLT 以适应父节点属性(<year value="">)?通过研究,一个答案说“我需要在创建元素之前添加属性创建”。这是有道理的,因为观察调试器,子节点是按 desc 顺序形成的,但是 year 标签缺少它的属性。但是我对 XSLT 真的一无所知。看不出它太复杂,但就是不懂语言。

任何帮助,非常感谢。谢谢

0 投票
2 回答
3534 浏览

html - 仅使用 XML 节点不同值填充下拉列表

我正在尝试生成一个可以与现有 XML 数据文件一起使用的搜索过滤器,并且我开始尝试在下拉列表框中仅显示来自其中一个节点的唯一值。

XML 文件的示例可以在... http://kirk.rapweb.co.uk/testing/filter/tidy/plain/products.xml看到

我已经设法使用 XSLT 以更易读的格式显示 XML ... http://kirk.rapweb.co.uk/testing/filter/tidy/products.xml

应用过滤器的相同数据... http://kirk.rapweb.co.uk/testing/filter/tidy/filter/products.xml

我想在第一个下拉列表框中列出的值被过滤掉...... http://kirk.rapweb.co.uk/testing/filter/tidy/distinct/products.xml

所有数据都拉入一个 HTML 页面... http://kirk.rapweb.co.uk/testing/filter/tidy/html/

我正在努力研究如何从... http://kirk.rapweb.co.uk/testing/filter/tidy/distinct/products.xml获取数据 到 HTML 页面下拉列表框中。

任何人都可以提供建议,指出正确的方向或确认我在正确的轨道上吗?

我想要达到的最终结果是有 2 个下拉框。

下拉列表 1 将包含...刹车、排气、照明

下拉列表 2 将包含...

  • 如果之前选择了制动器... 盘和鼓、垫和鞋。
  • 如果之前选择了排气... 中心,后部。
  • 如果之前选择了照明... 前照灯、尾灯。

现在我只想专注于用上面讨论的数据填充下拉框 1。

0 投票
1 回答
920 浏览

xml - XSLT 1.0 Find unique node with Highest value

I am beginner in XSLT 1.0. I am facing an issue when i tried to find unique node with Highest value.

Source XML:

As shown in above XML, There is a round trip result for A-B origin destination and i am going to purchase tickets for both the flights. i need to calculate total fare, fee (whichever is highest from both the Flights) and its total price.

Expected Output:

Here,

  • TotalFare is sum of all the Fare tag.
  • TotalFee is greater value of each passenger type multiply by no of passenger of that type.
  • e.g. For ADT greater Fee value is 25 and number of ADT is 2 so total Fee for ADT is 50. For CHD greater Fee value is 25 and number of CHD is 1 so total Fee for CHD is 25. That makes final total fee = 75.
  • TotalPrice is sum of ToatalFare and TotalFee attribute.

I've tried with below XSLT.

XSLT:

and got the below output.

Output:

TotalFee is not calculated correctly. Please Help. Thanks.

0 投票
1 回答
71 浏览

templates - xslt 通过调用模板进行分组

我是 xslt 的新手,正在尝试学习如何使用键和模板来学习分组。

有人可以帮助我如何在 xslt 中执行以下操作。我必须从另一个模板调用一个模板来进行转换。

谢谢

这是我的xml。

这是之后的样子。

0 投票
1 回答
479 浏览

xslt - XSLT GROUP BY 使用键

我正在尝试生成 HTML 输出,它是以下层次结构中的表 - DIVISION、DESK、STRATEGY。我需要在 Division 列和 Desk 列上设置行跨度。一个部门可以有多个办公桌,一个办公桌可以有多种策略。

我正在使用键来按 Division,Desk 定义分组。它适用于 Division,但适用于 Desk。请指教。

xml代码:

xslt:

0 投票
2 回答
395 浏览

xslt - 使用 XSLT 包装元素,但不包括最后匹配的元素

我正在尝试将旧的 XML 文件转换为新的改进结构。其中一部分需要我将一些松散的元素包装到父容器中,以及修改它们的子容器

旧结构

新结构

我找到了这个答案并对其进行了一些修改以满足我的需要:

但我的输出是:

我正在使用 PHP5 的内置 XSLTProcessor 对象 - 所有 XML 和 XSL 都是 1.0 版

0 投票
2 回答
2297 浏览

xml - 尝试使用 XSLT 从 XML 创建 HTML 表

我正在努力使用 XSLT。我被困在程序领域。基本上我有一些从数据库生成的 XML,看起来有点像这样:

我试图以 HTML 表中的读数结束,每个传感器都是一列,每一行的时间都在左侧,如下所示:

Although the order of the time-slots is guaranteed to be ascending so I don't need to sort them (there could be 1000's), the problem is that within each time-slot the order of the sensors cannot be guaranteed, so I thought I would loop through the sensors I used to create the table headers each time and select the correct sensor from each slot as I iterate through the slots. Although this doesn't work you'll probably get what I tried to do (I realise now why it doesn't work.. variables do not behave how I expected!) : -

There can be 100's or even 1000's of time-slots, this is just a small example. I can adjust the hierarchy of the XML if it helps, but I cannot put the sensors in order within each time-slot without some serious rework of the database query. I'm hoping that isn't necessary.

Originally I had XML where the slots were separated out like this:

Which involved a much simpler database query! Here I could guarantee the order, but the XQuery processor I'm using (Qt's QXmlQuery) does not support for-each-group so I could not find a way to group based on time.

Sorry this is so long, I hope someone can help at least point me in the right direction.

Thanks.

0 投票
1 回答
729 浏览

xml - 使用 xslt 对元素进行分组

我想在 xsl 文件中使用函数“group by”,但我只是收到错误。

这是我的代码:

错误是这个:

msxml3.dll 错误“80004005”

“关键字表可能不包含 xsl:for-each-group”。

xml是这样的:

0 投票
1 回答
710 浏览

xslt - XSL 1.0 双重分组

这是我在这里的第一个问题。

我想使用 XSL 1.0 转换这个 xml:

进入这个:

我已经尝试过使用 Muenchian Method,但是这只允许我按 GROUP 排序,并且我无法按 SUBGROUP 对排序结果进行排序。请注意,每个组/子组我只能查看一次标题。

@CM Sperberg-麦昆

我不想贴一堵文字墙,但如果它可能有助于我这样做:

这是我尝试过的解决方案之一:

我尝试使用 preceiding-sibling 来测试是否查看 SUBGROUP 但我发现遍历节点是不可能的,所以这可能不是一个好方法。