开发者

datetime grouping problem in XSLT

开发者 https://www.devze.com 2023-03-30 21:46 出处:网络
I can\'t seem to get my head around this, any help would be greatly appreciated: I have a list of datetime nodes, grouped by day (for-each-group),

I can't seem to get my head around this, any help would be greatly appreciated: I have a list of datetime nodes, grouped by day (for-each-group),

<xsl:for-each-group select="response/result/doc" 
group-by="functx:day-of-week(xs:dateTime(./date[@name='ds_startshow']))">

This works fine, the datetimes are grouped by day of the week. The problem is that I need to include some datetime nodes of the next day to the current day. For example: I need to include saturday 0:15 to the friday "group" (the early hours belong to the previous day). So a single day stretches out to some some hours of the next morning. Basically, a new day starts at 2:00 instead of 0:00. How would I accomplish a grouping like that with XSLT(2). Presumably I need to write a fun开发者_StackOverflow社区ction to tackle this? Do I need to iterate over the days? Not sure about the best practice in this particular case.


What you want to do is take the actual time and subtract two hours, thus creating a virtual day boundary at 02:00, and then group by that. This is untested, but you might try:

$x - xs:dayTimeDuration("PT2H")

where $x is the actual time. The result is the actual time minus 2 hours, which you can then use to group by.

You might look at this site, which I found by googling for "xslt date arithmetic", and is where I found the syntax for xs:dayTimeDuration()

0

精彩评论

暂无评论...
验证码 换一张
取 消