troubleshooting Question

Can I extrapolate an element into multiple elements using xslt?

Avatar of isvensen
isvensen asked on
Web Languages and StandardsXML
8 Comments1 Solution198 ViewsLast Modified:
Hi,

I have an element in an xml that looks like this:

<forecast start_hr="1" start_int="1" end_hr="24" end_int="2" value="200"/>
Now I need that to be extrapolated to be:
<forecast start_hr="1" start_int="1" end_hr="1" end_int="1" value="200"/>
<forecast start_hr="1" start_int="2" end_hr="1" end_int="2" value="200"/>
<forecast start_hr="2" start_int="1" end_hr="2" end_int="1" value="200"/>
<forecast start_hr="2" start_int="2" end_hr="2" end_int="2" value="200"/>
<forecast start_hr="3" start_int="1" end_hr="3" end_int="1" value="200"/>
<forecast start_hr="3" start_int="2" end_hr="3" end_int="2" value="200"/>
<forecast start_hr="4" start_int="1" end_hr="4" end_int="1" value="200"/>
<forecast start_hr="4" start_int="2" end_hr="4" end_int="2" value="200"/>
...
<forecast start_hr="24" start_int="1" end_hr="24" end_int="1" value="200"/>
<forecast start_hr="24" start_int="2" end_hr="24" end_int="2" value="200"/>

Basically create an element for every half hour of the day in the given format. Of course, there's no guarantee that there's always 24 elements, so I need to dynamically use the end_hr and end_int of the original element like this (pseudocode)

iterations=(end_hr - start_hr +1) * 2;
if (start_hr = 2)  = iterations -1;
if (end_hr = 1)  = iterations -1;

prev_start_hr = start_hr;
prev_start_int = start_int;
for (i=1;i<iterations;i++)
{
<forecast start_hr=prev_start_hr start_int=prev_start_int end_hr=prev_start_hr end_int=prev_start_int value=value/>
if (prev_int = 1) prev_int = 2 else prev_hr++;
}

Any way I can do this in xslt?
ASKER CERTIFIED SOLUTION
Gertone (Geert Bormans)
Information Architect
Join our community to see this answer!
Unlock 1 Answer and 8 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 8 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros