I have the following xml file. And I need to remove the end date of the each node if the end date is the start date of another node.
<time_Off_Event_group>
<StartDate>20211206</StartDate>
<EndDate>20211207</EndDate>
</time_Off_Event_group>
<time_Off_Event_group>
<StartDate>20211209</StartDate>
<EndDate>20211210</EndDate>
</time_Off_Event_group>
<time_Off_Event_group>
<StartDate>20211210</StartDate>
<EndDate>20211211</EndDate>
</time_Off_Event_group>
The expect xml information should be like this. Can this be done be the xlst?
<time_Off_Event_group>
<StartDate>20211206</StartDate>
<EndDate>20211207</EndDate>
</time_Off_Event_group>
<time_Off_Event_group>
<StartDate>20211209</StartDate>
<EndDate>20211211</EndDate>
</time_Off_Event_group>
CodePudding user response:
Judging from your example, you are actually trying to merge adjacent nodes if the end date of the first one is the same as the start date of the second. Presumably there can be more than two such nodes in a group.
If that's a correct interpretation, I would use
<xsl:for-each-group select="time_Off_Event_group"
group-starting-with="*[not(StartDate = preceding-sibling::*[1]/EndDate)]">
<time_Off_Event_group>
<StartDate>
<xsl:value-of select="current-group()[1]/StartDate"/>
</StartDate>
<EndDate>
<xsl:value-of select="current-group()[last()]/EndDate"/>
</EndDate>
</time_Off_Event_group>
</xsl:for-each-group>
But you haven't specified your requirement very clearly so this may be a wild guess.