获取基于 Day XSLT2.0/XSLT3.0 的日期和地图值列表
我有这样的场景,其中:
需要列出开始日期和结束日期之间的日期,并且基于“每周”或“双周”类型需要将日期节点(星期一、星期二...)映射到相应的日期。
Week1 是 StartDate 的周,Week2 是 StartDate 的第二周(Week1 后的周)
如果类型为 Weekly: 需要将 Day 节点值从 Week1 节点映射到该周的相应日期,并不断重复直到 EndDate
如果类型为 Bi-Weekly: 需要映射前两周的 Week1 节点和 Week2 节点的节点值,并不断重复直到结束日期
StartDate 可以是一周中的任何一天,不一定是一周的开始(星期一)。
下面是我的 XML:
<Data>
<Root>
<Type>Bi-Weekly</Type>
<StartDate>2022-02-22</StartDate>
<EndDate>2022-12-31</EndDate>
<Week1>
<Monday>4</Monday>
<Tuesday>0</Tuesday>
<Wednesday>4</Wednesday>
<Thursday>0</Thursday>
<Friday>4</Friday>
</Week1>
<Week2>
<Monday>0</Monday>
<Tuesday>4</Tuesday>
<Wednesday>0</Wednesday>
<Thursday>4</Thursday>
<Friday>0</Friday>
</Week2>
</Root>
<Root>
<Type>Weekly</Type>
<StartDate>2023-02-12</StartDate>
<EndDate>2023-12-15</EndDate>
<Week1>
<Monday>4</Monday>
<Tuesday>0</Tuesday>
<Wednesday>4</Wednesday>
<Thursday>0</Thursday>
<Friday>4</Friday>
</Week1>
<Week2>
<Monday>0</Monday>
<Tuesday>4</Tuesday>
<Wednesday>0</Wednesday>
<Thursday>4</Thursday>
<Friday>0</Friday>
</Week2>
</Root>
</Data>
我想要的双周输出是:
22-Feb-22|Tuesday|0
23-Feb-22|Wednesday|4
24-Feb-22|Thursday|0
25-Feb-22|Friday|4
28-Feb-22|Monday|0
1-Mar-22|Tuesday|4
2-Mar-22|Wednesday|0
3-Mar-22|Thursday|4
4-Mar-22|Friday|0
.
.
.
20-Dec-22|Tuesday|4
21-Dec-22|Wednesday|0
22-Dec-22|Thursday|4
23-Dec-22|Friday|0
26-Dec-22|Monday|4
27-Dec-22|Tuesday|0
28-Dec-22|Wednesday|4
29-Dec-22|Thursday|0
30-Dec-22|Friday|4
我想要的每周输出是:
22-Feb-22|Tuesday|0
23-Feb-22|Wednesday|4
24-Feb-22|Thursday|0
25-Feb-22|Friday|4
28-Feb-22|Monday|4
1-Mar-22|Tuesday|0
2-Mar-22|Wednesday|4
3-Mar-22|Thursday|0
4-Mar-22|Friday|4
7-Mar-22|Monday|4
8-Mar-22|Tuesday|0
.
.
.
19-Dec-22|Monday|4
20-Dec-22|Tuesday|0
21-Dec-22|Wednesday|4
22-Dec-22|Thursday|0
23-Dec-22|Friday|4
26-Dec-22|Monday|4
27-Dec-22|Tuesday|0
28-Dec-22|Wednesday|4
29-Dec-22|Thursday|0
30-Dec-22|Friday|4
另外 。 。删除输出中值为“0”的日期会有所帮助。
如果可以使过程变得简单,则可以修改输入文件的结构,例如
<Data>
<Root>
<Type>Bi-Weekly</Type>
<StartDate>2022-02-21</StartDate>
<EndDate>2022-12-31</EndDate>
<Week>
<W1Monday>4</W1Monday>
<W1Tuesday>0</W1Tuesday>
<W1Wednesday>4</W1Wednesday>
<W1Thursday>0</W1Thursday>
<W1Friday>4</W1Friday>
<W2Monday>0</W2Monday>
<W2Tuesday>4</W2Tuesday>
<W2Wednesday>0</W2Wednesday>
<W2Thursday>4</W2Thursday>
<W2Friday>0</W2Friday>
</Week>
</Root>
</Data>
谢谢!
I have this scenario wherein:
Need to list the dates between the Start Date and End Date and based on Type being 'Weekly' or 'Bi-Weekly' need to map the Day Nodes (Monday,Tuesday...) to the corresponding dates.
Week1 is the week of StartDate and Week2 is the second week of StartDate (the week after Week1)
If Type is Weekly:
Need to map Day node values from Week1 node to corresponding dates of that week and keep repeating until EndDate
If Type is Bi-Weekly:
Need to map node values from Week1 node and Week2 node for the first two weeks and keep repeating until End Date
StartDate can be any day of the week and not necessarily be on beginning of week (Monday).
Below is my XML:
<Data>
<Root>
<Type>Bi-Weekly</Type>
<StartDate>2022-02-22</StartDate>
<EndDate>2022-12-31</EndDate>
<Week1>
<Monday>4</Monday>
<Tuesday>0</Tuesday>
<Wednesday>4</Wednesday>
<Thursday>0</Thursday>
<Friday>4</Friday>
</Week1>
<Week2>
<Monday>0</Monday>
<Tuesday>4</Tuesday>
<Wednesday>0</Wednesday>
<Thursday>4</Thursday>
<Friday>0</Friday>
</Week2>
</Root>
<Root>
<Type>Weekly</Type>
<StartDate>2023-02-12</StartDate>
<EndDate>2023-12-15</EndDate>
<Week1>
<Monday>4</Monday>
<Tuesday>0</Tuesday>
<Wednesday>4</Wednesday>
<Thursday>0</Thursday>
<Friday>4</Friday>
</Week1>
<Week2>
<Monday>0</Monday>
<Tuesday>4</Tuesday>
<Wednesday>0</Wednesday>
<Thursday>4</Thursday>
<Friday>0</Friday>
</Week2>
</Root>
</Data>
My desired output for Bi-Weekly is:
22-Feb-22|Tuesday|0
23-Feb-22|Wednesday|4
24-Feb-22|Thursday|0
25-Feb-22|Friday|4
28-Feb-22|Monday|0
1-Mar-22|Tuesday|4
2-Mar-22|Wednesday|0
3-Mar-22|Thursday|4
4-Mar-22|Friday|0
.
.
.
20-Dec-22|Tuesday|4
21-Dec-22|Wednesday|0
22-Dec-22|Thursday|4
23-Dec-22|Friday|0
26-Dec-22|Monday|4
27-Dec-22|Tuesday|0
28-Dec-22|Wednesday|4
29-Dec-22|Thursday|0
30-Dec-22|Friday|4
My desired output for Weekly is:
22-Feb-22|Tuesday|0
23-Feb-22|Wednesday|4
24-Feb-22|Thursday|0
25-Feb-22|Friday|4
28-Feb-22|Monday|4
1-Mar-22|Tuesday|0
2-Mar-22|Wednesday|4
3-Mar-22|Thursday|0
4-Mar-22|Friday|4
7-Mar-22|Monday|4
8-Mar-22|Tuesday|0
.
.
.
19-Dec-22|Monday|4
20-Dec-22|Tuesday|0
21-Dec-22|Wednesday|4
22-Dec-22|Thursday|0
23-Dec-22|Friday|4
26-Dec-22|Monday|4
27-Dec-22|Tuesday|0
28-Dec-22|Wednesday|4
29-Dec-22|Thursday|0
30-Dec-22|Friday|4
Additionally . . Getting rid of Dates with value as '0' in the output will help.
The structure of input file can be modified if it will make the process easy such as
<Data>
<Root>
<Type>Bi-Weekly</Type>
<StartDate>2022-02-21</StartDate>
<EndDate>2022-12-31</EndDate>
<Week>
<W1Monday>4</W1Monday>
<W1Tuesday>0</W1Tuesday>
<W1Wednesday>4</W1Wednesday>
<W1Thursday>0</W1Thursday>
<W1Friday>4</W1Friday>
<W2Monday>0</W2Monday>
<W2Tuesday>4</W2Tuesday>
<W2Wednesday>0</W2Wednesday>
<W2Thursday>4</W2Thursday>
<W2Friday>0</W2Friday>
</Week>
</Root>
</Data>
Thanks!
Current Code : https://xsltfiddle.liberty-development.net/nbspVb7/4
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
看看这是否有帮助:
XSLT 2.0
这需要调整以适应Weekly - 但这应该不会太困难。另外,如果我没有记错的话,它假设
StartDate
始终是星期一。演示:https://xsltfiddle.liberty-development.net/nbspVb7 /5
See if this can help:
XSLT 2.0
This needs adjustment to accommodate
<Type>Weekly</Type>
- but that shouldn't be too difficult. Also, if I am not mistaken, it assumes thatStartDate
is always a Monday.Demo: https://xsltfiddle.liberty-development.net/nbspVb7/5