B
Bostonasian
I find this challenging task(maybe because I am fairly new to XSLT).
I've got followoing xml.
<Events>
<Event ID="1" City="New York" StateID="1" State="NY"
Date="9/17/2005"/>
<Event ID="2" City="Dallas" StateID="2" State="TX"
Date="9/17/2005"/>
<Event ID="3" City="Chicago" StateID="3" State="IL"
Date="9/17/2005"/>
<Event ID="4" City="San Diego" StateID="4" State="CA"
Date="9/17/2005"/>
<Event ID="5" City="Albany" StateID="1" State="NY"
Date="9/17/2005"/>
<Event ID="6" City="Los Angeles" StateID="4" State="CA"
Date="9/17/2005"/>
</Events>
And I have to change into following
<States>
<State ID="1" Name="NY">
<Events>
<Event ID="1" City="New York" StateID="1" State="NY"
Date="9/17/2005"/>
<Event ID="5" City="Albany" StateID="1" State="NY"
Date="9/17/2005"/>
</Events>
</State>
<State ID="2" Name="TX">
<Events>
<Event ID="2" City="Dallas" StateID="2" State="TX"
Date="9/17/2005"/>
</Events>
</State>
<State ID="3" Name="IL">
<Events>
<Event ID="3" City="Chicago" StateID="3" State="IL"
Date="9/17/2005"/>
</Events>
</State>
<State ID="4" Name="CA">
<Events>
<Event ID="4" City="San Diego" StateID="4" State="CA"
Date="9/17/2005"/>
<Event ID="6" City="Los Angeles" StateID="4" State="CA"
Date="9/17/2005"/>
</Events>
</State>
</States>
And don't ask me why. I am not responsible and both schemas are those
two diffenrent clients have been using and I have no control of
changing them. Only control I have is XSLT.
I was able to sort by state.
Then In use foreach to loop, then I did something like
if StateID != PrevStateID then create new instance of "State"&"Events"
element. But I haven't been successful.
Can anyone help?
I've got followoing xml.
<Events>
<Event ID="1" City="New York" StateID="1" State="NY"
Date="9/17/2005"/>
<Event ID="2" City="Dallas" StateID="2" State="TX"
Date="9/17/2005"/>
<Event ID="3" City="Chicago" StateID="3" State="IL"
Date="9/17/2005"/>
<Event ID="4" City="San Diego" StateID="4" State="CA"
Date="9/17/2005"/>
<Event ID="5" City="Albany" StateID="1" State="NY"
Date="9/17/2005"/>
<Event ID="6" City="Los Angeles" StateID="4" State="CA"
Date="9/17/2005"/>
</Events>
And I have to change into following
<States>
<State ID="1" Name="NY">
<Events>
<Event ID="1" City="New York" StateID="1" State="NY"
Date="9/17/2005"/>
<Event ID="5" City="Albany" StateID="1" State="NY"
Date="9/17/2005"/>
</Events>
</State>
<State ID="2" Name="TX">
<Events>
<Event ID="2" City="Dallas" StateID="2" State="TX"
Date="9/17/2005"/>
</Events>
</State>
<State ID="3" Name="IL">
<Events>
<Event ID="3" City="Chicago" StateID="3" State="IL"
Date="9/17/2005"/>
</Events>
</State>
<State ID="4" Name="CA">
<Events>
<Event ID="4" City="San Diego" StateID="4" State="CA"
Date="9/17/2005"/>
<Event ID="6" City="Los Angeles" StateID="4" State="CA"
Date="9/17/2005"/>
</Events>
</State>
</States>
And don't ask me why. I am not responsible and both schemas are those
two diffenrent clients have been using and I have no control of
changing them. Only control I have is XSLT.
I was able to sort by state.
Then In use foreach to loop, then I did something like
if StateID != PrevStateID then create new instance of "State"&"Events"
element. But I haven't been successful.
Can anyone help?