evaluating time and building a sequence of values
<units>
<unit>
<start>2009-04-16T00:00:00-05:00</start>
<end>2009-04-16T02:00:00-05:00</end>
<value>35</value>
</unit>
<unit>
<start>2009-04-16T02:00:00-05:00</start>
<end>2009-04-16T05:00:00-05:00</end>
<value>40</value>
</unit>
<unit>
<start>2009-04-16T22:00:00-05:00</start>
<end>2009-04-17T00:00:00-05:00</end>
<value>44</value>
</unit>
</units>
Desired result would be a sequence of 24 values captured in a variable so that it can be iterated thru later:
35 35 40 40 40 null null null null null null null null null null null null null null null null null 44 44
Currently, I am using the following code, but thought there might be a more efficient way to solve this problem:
<xsl:variable name="values" select="for $i in (1 to 24) return if (units/unit[$i gt (hours-from-dateTime(start))][$i lt (if (hours-from-dateTime(end) eq 0) then 25 else hours-from-dateTime(end) + 1)]) then format-number(units/unit[$i gt (hours-from-dateTime(start) )][$i lt (if (hours-from-dateTime(end) eq 0) then 25 else hours-from-dateTime(end) + 1)]/value, '######.##') else 'null'"/>
Any suggestions are greatly appreciated.
Thanks!
|