Transforming XML to CSV using XSLT 1.0

supahfly

New Member
I have a special case of transforming a XML document to a CSV document.In my XML I have the following structure:\[code\]<Pictures> <Picture> <File>picture1.jpg</File> <Purpose>normal</Purpose> </Picture> <Picture> <File>pictureX.jpg</File> <Purpose>normal</Purpose> </Picture> <Picture> <File>picture999.jpg</File> <Purpose>normal</Purpose> </Picture> <Picture> <File>picture1.jpg</File> <Purpose>normal</Purpose> </Picture> <Picture> <ID>555</ID> <File>detailX.jpg</File> <Purpose>detail</Purpose> </Picture> <Picture> <File>detail1.jpg</File> <Purpose>detail</Purpose> </Picture></Pictures>\[/code\]What I want is the followind CSV:\[code\]normal1;normal2;normal3;detail1;detail2picture1.jpg;pictureX.jpg;picture999.jpg;\[/code\]Up to this point I am able to convert it correctly. But the problem is, that there are many other Pictures elements in my XML that can contain Picture elements with other purpose values.Example:\[code\]<Pictures> <Picture> <File>picture1.jpg</File> <Purpose>normal</Purpose> </Picture></Picture><Pictures> <Picture> <File>picture2.jpg</File> <Purpose>detail</Purpose> </Picture></Picture><Pictures> <Picture> <File>pictureX.jpg</File> <Purpose>normal</Purpose> </Picture> <Picture> <File>pictureY.jpg</File> <Purpose>detail</Purpose> </Picture></Picture><Pictures> <Picture> <File>pictureA.jpg</File> <Purpose>normal</Purpose> </Picture> <Picture> <File>pictureB.jpg</File> <Purpose>normal</Purpose> </Picture> <Picture> <File>pictureD.jpg</File> <Purpose>detail</Purpose> </Picture></Picture>\[/code\]As CSV:\[code\]normal1;normal2;detail1picture1.jpg;;;;picture2.jpg;pictureX.jpg;;pictureY.jpgpictureA.jpg;pictureB.jpg;pictureD.jpg\[/code\]I have no Idea if it possible to do that only by using XSLT or how to do. The transformation has to be fast (one XML can easily contain 38k Pictures elements) .If anyone have an idea please post.Thank you in advance!Andr
 
Back
Top