如何在 XSLT 中按日期范围对项目进行分组?
我有一堆看起来有点像这样的数据:
<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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您可以使用 EXSLT 日期和时间函数,您可以使用类似以下内容按库存时间获取商品(以周为单位,四舍五入):
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):