Wednesday, 21 August 2013

XSL Reversing the order with a counter

XSL Reversing the order with a counter

I have a very unusual scenario. Never heard or done something like this
before. Here's my source XML.
<?xml version="1.0" encoding="UTF-8"?>
<ListItems>
<List>
<name>A<name/>
</List>
<List>
<name>B<name/>
</List>
<List>
<name>C<name/>
</List>
<List>
<name>D<name/>
</List>
</ListItems>
What I am looking to do is to reverse the order of the list with a reverse
counter added as an index. The resultant XML should look like this:
<UpdateListItems>
<List>
<name>D<name/>
<index>4<index/>
</List>
<List>
<name>C<name/>
<index>3<index/>
</List>
<List>
<name>B<name/>
<index>2<index/>
</List>
<List>
<name>A<name/>
<index>1<index/>
</List>
</UpdateListItems>
Notice the names in reverse order with an index added in reverse order.
Sounds a bit stupid but is it possible to do this in xml transformation?

No comments:

Post a Comment