如何在 XSLT 中按日期范围对项目进行分组?

发布于 2024-08-12 07:25:10 字数 1383 浏览 4 评论 0原文

我有一堆看起来有点像这样的数据:

<item>
  <colour>Red</colour>
  <date_created>2009-10-10 12:01:55</date_created>
  <date_sold>2009-10-20 22:32:12</date_sold>
</item>
<item>
  <colour>Blue</colour>
  <date_created>2009-11-01 13:21:00</date_created>
  <date_sold>2009-11-21 12:32:12</date_sold>
</item>
<item>
  <colour>Blue</colour>
  <date_created>2009-10-29 21:23:02</date_created>
  <date_sold>2009-10-20 02:02:22</date_sold>
</item>
<item>
  <colour>Red</colour>
  <date_created>2009-11-02 09:11:51</date_created>
  <date_sold>2009-11-20 09:15:53</date_sold>
</item>
<item>
  <colour>Red</colour>
  <date_created>2009-10-18 11:00:55</date_created>
  <date_sold>2009-10-20 11:12:22</date_sold>
</item>

现在我想做的是通过 XSLT 样式表运行它,这样我得到的输出看起来像这样:

Colour | In stock 1 week | In stock 2 weeks | In stock 3 weeks
Red    |       1         |        3         |       2
Blue   |       0         |        2         |       1

目前我有一个使用基本 muenchian 分组的样式表显示 30% 的库存是红色,70% 是蓝色,但我找不到找到给定日期范围内的节点数量的方法。

有没有办法使用按键来选择范围?我需要创建某种中间数据节点吗?是否有不同的路线表明我用这两个建议吠叫了错误的树?这对于 XSLT 是否可行,或者我是否需要找到一种方法来更改数据源?

I have a bunch of data that looks a little like this:

<item>
  <colour>Red</colour>
  <date_created>2009-10-10 12:01:55</date_created>
  <date_sold>2009-10-20 22:32:12</date_sold>
</item>
<item>
  <colour>Blue</colour>
  <date_created>2009-11-01 13:21:00</date_created>
  <date_sold>2009-11-21 12:32:12</date_sold>
</item>
<item>
  <colour>Blue</colour>
  <date_created>2009-10-29 21:23:02</date_created>
  <date_sold>2009-10-20 02:02:22</date_sold>
</item>
<item>
  <colour>Red</colour>
  <date_created>2009-11-02 09:11:51</date_created>
  <date_sold>2009-11-20 09:15:53</date_sold>
</item>
<item>
  <colour>Red</colour>
  <date_created>2009-10-18 11:00:55</date_created>
  <date_sold>2009-10-20 11:12:22</date_sold>
</item>

Now what I would like to be able to do is to run that through an XSLT stylesheet such that I get ouput looking like this:

Colour | In stock 1 week | In stock 2 weeks | In stock 3 weeks
Red    |       1         |        3         |       2
Blue   |       0         |        2         |       1

Currently I have a stylesheet that uses basic muenchian grouping to show that 30% of stock was Red and 70% blue, but I can't see a way to find the number of nodes withing a given date range.

Is there a way to use keys to select a range? Do I need to create some kind of intermediate data node? Is there a different route that shows I'm barking up the wrong tree with both those suggestions? Is this even possible with XSLT or do I need to find a way to change the data source?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

安稳善良 2024-08-19 07:25:10

如果您可以使用 EXSLT 日期和时间函数,您可以使用类似以下内容按库存时间获取商品(以周为单位,四舍五入):

<xsl:key 
  name="items-by-weeks-in-stock" 
  match="//item"
  use="ceiling(date:seconds(date:difference(translate(date_created, ' ', 'T'),
                                            translate(date_sold, ' ', 'T')))
               div 604800)"/>

If you can use EXSLT date and time functions, you could use something like the following to get items by time in stock (in weeks, rounded up):

<xsl:key 
  name="items-by-weeks-in-stock" 
  match="//item"
  use="ceiling(date:seconds(date:difference(translate(date_created, ' ', 'T'),
                                            translate(date_sold, ' ', 'T')))
               div 604800)"/>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文