I have an XML like this:
<xml version="1.0" encoding="UTF-8"?>
<countries>
<country>
<name>Latvia</name>
</country>
<country>
<name>USA</name>
</country>
<country>
<name>Australia</name>
</country>
<country>
<name>Indonesia</name>
</country>
<country>
<name>UK</name>
</country>
<country>
<name>India</name>
</country>
<country>
<name>Argentina</name>
</country>
<country>
<name>Chile</name>
</country>
<country>
<name>Singapore</name>
</country>
<country>
<name>New Zeland</name>
</country>
<country>
<name>Kenya</name>
</country>
<country>
<name>Zambia</name>
</country>
<country>
<name>Tunisia</name>
</country>
</countries>
Now I want to create alphabetical index of countries in 3 columns. Each column will contain the number of alpha as one third of the starting alphabets present and its corresponding countries.
Last column can have the rest of them if number of starting alphabets present happens to be not divisible by 3.
For example, here we have country names starting with L, C, U, A, I, S, N, K, Z and T.
After arranging: A C I K L N S T U Z
Now, my index will have:
Column1: A, C and I countries
Column2: K, L and N countries
Column3: S, T, U and Z countries
Hence the desired output is:
<countries>
<column1>
<A>
<country>
<name>Argentina</name>
</country>
<country>
<name>Australia</name>
</country>
</A>
<C>
<country>
<name>Chile</name>
</country>
</C>
<I>
<country>
<name>India</name>
</country>
<country>
<name>Indonesia</name>
</country>
</I>
</column1>
<column2>
<K>
<country>
<name>Kenya</name>
</country>
</K>
<L>
<country>
<name>Latvia</name>
</country>
</L>
<N>
<country>
<name>New Zeland</name>
</country>
</N>
</column2>
<column3>
<S>
<country>
<name>Singapore</name>
</country>
</S>
<T>
<country>
<name>Tunisia</name>
</country>
</T>
<U>
<country>
<name>UK</name>
</country>
<country>
<name>USA</name>
</country>
</U>
<Z>
<country>
<name>Zambia</name>
</country>
</Z>
</column3>
</countries>
Please help. I am using xslt 2.0.