我有一个要根据时间戳信息按时间间隔分组的项目列表(在以下示例中,startdate)。例如,byc间隔为3秒。
例如:
<ListItem>
<item>
<id>1</id>
<startdate>2002-05-30T09:30:10.025+01:00</startdate>
</item>
<item>
<id>2</id>
<startdate>2002-05-30T09:30:11.025+01:00</startdate>
</item>
<item>
<id>3</id>
<startdate>2002-05-30T09:30:13.025+01:00</startdate>
</item>
<item>
<id>4</id>
<startdate>2002-05-30T09:30:14.025+01:00</startdate>
</item>
<item>
<id>5</id>
<startdate>2002-05-30T09:30:17.025+01:00</startdate>
</item>
</ListItem>
预期结果是:
<ItemmGroupe>
<groupe>
<item>
<id>1</id>
<startdate>2002-05-30T09:30:10.025+01:00</startdate>
</item>
<item>
<id>2</id>
<startdate>2002-05-30T09:30:11.023+01:00</startdate>
</item>
<item>
<id>3</id>
<startdate>2002-05-30T09:30:13.020+01:00</startdate>
</item>
</groupe>
<groupe>
<item>
<id>4</id>
<startdate>2002-05-30T09:30:14.027+01:00</startdate>
</item>
</groupe>
<groupe>
<item>
<id>5</id>
<startdate>2002-05-30T09:30:17.025+01:00</startdate>
</item>
</groupe>
</ItemGroupe>
如何使用xslt转换做到这一点?
答案 0 :(得分:1)
使用XSLT 2.0,您可以使用
<xsl:for-each-group select="item"
group-adjacent="my:timeSlot(xs:dateTime(startDate))">
<groupe>
<xsl:copy-of select="current-group()"/>
...
my:timeSlot
计算的地方:
xs:integer(($startDate - xs:dateTime('2000-01-01T00:00:00Z'))
div xs:dayTimeDuration('PT3S'))