I have an XML feed of events whose dates I would like to interact with.
Source XML:
<?xml version="1.0" encoding="UTF-8"?>
<events>
<event>
<!-- various elements -->
<start_datetime value="2012-02-09 10:00:00"/>
<end_datetime value="2012-02-09 11:00:00"/>
<!-- various elements -->
</event>
<event>
<!-- various elements -->
<start_datetime value="2012-02-09 10:00:00"/>
<end_datetime value="2012-02-10 15:00:00"/>
<!-- various elements -->
</event>
<!-- other events -->
</events>
Notice that /events/event[1]
is an event that starts and ends on the same day; /events/event[2]
, on the other hand, spans two days. Here's what I would like to accomplish:
- For events that are on the same day, leave the datetimes alone and merely transform those attributes into child elements.
- For events that span multiple days, I want to create multiple
<event>
elements that (a) match the overall span of time and (b) where appropriate, span a full day's worth of time.
So, my ideal XSLT would produce:
Desired XML:
<?xml version="1.0" encoding="UTF-8"?>
<events>
<event>
<!-- various elements -->
<start_datetime>2012-02-09 10:00:00</start_datetime>
<end_datetime>2012-02-09 11:00:00</end_datetime>
<!-- various elements -->
</event>
<event>
<!-- various elements -->
<start_datetime>2012-02-09 10:00:00</start_datetime>
<end_datetime>2012-02-09 23:59:59</end_datetime>
<!-- various elements -->
</event>
<event>
<!-- various elements -->
<start_datetime>2012-02-10 00:00:00</start_datetime>
<end_datetime>2012-02-10 15:00:00</end_datetime>
<!-- various elements -->
</event>
<!-- other events -->
</events>
Notice how my rules are met:
- Because
/events/event[1]
occurs over the same day, we leave it alone (other than the trivial task of changing attribute values into child elements). /events/event[2]
spans two days, which means it needs two<event>
blocks (one from the starting datetime to 11:59:59pm on that date and one from 00:00:00 on the ending date to the ending datetime).
Final Considerations:
This needs to be accomplished in XSLT 1.0.
I am not opposed to using EXSLT's date functions - however, if they can be avoided, that would be preferable.
Clear as mud? As always, thanks for your help. :)