I have a source xml that looks something like this:
<item>
<id>1</id>
<property name="representative_email"><value>Jallu.Kola@foo.bar.com</value></property>
<property name="representative_name"><value>Jallu Kola</value></property>
<property name="representative_phone"><value>555 123 456</value></property>
<property name="representative_email"><value>Sala.Rakas@foo.bar.com</value></property>
<property name="representative_name"><value>Sala Rakas</value></property>
<property name="representative_phone"><value>555 2314 124</value></property>
</item>
<item>
<id>2</id>
<property name="representative_email"><value>Sala.Rakas@foo.bar.com</value></property>
<property name="representative_name"><value>Sala Rakas</value></property>
<property name="representative_phone"><value>555 2314 124</value></property>
</item>
<item>
<id>3</id>
<property name="representative_email"><value>Jallu.Kola@foo.bar.com</value></property>
<property name="representative_name"><value>Jallu Kola</value></property>
<property name="representative_phone"><value>555 123 456</value></property>
<property name="representative_email"><value>Sala.Rakas@foo.bar.com</value></property>
<property name="representative_name"><value>Sala Rakas</value></property>
<property name="representative_phone"><value>555 2314 124</value></property>
<property name="representative_email"><value>ville.kalle@foo.bar.com</value></property>
<property name="representative_name"><value>Ville Kalle</value></property>
<property name="representative_phone"><value>555 124 124124</value></property>
</item>
Unfortunately there’s not much I can do about this other than use xslt to convert it to something more sensible.
I would like to convert it to look like this:
<item>
<id>
<representatives>
<representative>
<email></email>
<name></name>
</phone></phone>
</representative
</representatives
</item>
Any ideas how this can be achieved with xslt?I’m thinking that I need to collect the representative_* elements into memory while procedding an element. Once the end of that item element is reached, I should output the new element. Under that I would need to create a element for each group of the email+name+phone elements that appear in sequence.
So, if each group always contain all 3 elements, you could iterate over one of them then select others by the same position: