Re: [xsl] How to "flatten" a XML file with n-ary Cartesian product over n sequences X1, ..., Xn using XSL

Subject: Re: [xsl] How to "flatten" a XML file with n-ary Cartesian product over n sequences X1, ..., Xn using XSL
From: Martin Honnen <Martin.Honnen@xxxxxx>
Date: Fri, 28 Aug 2009 20:09:09 +0200
reynaldo.rizzo@xxxxxxxxxxxxxxxx wrote:

The desired output is a delimited file shown as follows:

'output.csv'
root,itemCode,itemName,aCode,aDescription,bCode,bDescription,cCode,cDescription

That line has nine items while the lines below have only eight items each.


01,name0,10,description0,100,description2,996,description4
01,name0,10,description0,100,description2,997,description5
01,name0,10,description0,200,description3,996,description4
01,name0,10,description0,200,description3,997,description5
02,name1,20,description6,null,null,998,description10
02,name1,20,description6,null,null,999,description11

Output is the Cartesian product of each item with its own sub-sequences.

I've had limited success with my own limited self-learned XSL skills dealing on a per case basis, but I'm not satisfied with the efficiency achieved. Because I have no "normalized" approach, complexity of my XSL grows considerably, related to the number of sequences involved and I'm getting stuck when it involves more than three.

I was wondering if there is any "standard" method that solves this problem for n-sequences (i.e. using a <xsl:for-each-group> that groups by item and repeat the contents for each sublist?) so I could use recursion or iterations according to n. Please note that sequences are optional; the schema allows for empty or nonexistent sequences, where in such cases 'null' must be output for the missing fields.

And what determines the complete number of sequences?


--

	Martin Honnen
	http://msmvps.com/blogs/martin_honnen/

Current Thread