Subject: [xsl] XSLT grouping problem From: "Aksish" <aksish@xxxxxxxxxxxxx> Date: Sun, 11 Jun 2006 20:50:35 -0700 |
I have xml input files in the following format Music categoryFilter="rock,pop,r&b,country,latin" yearsFilter="97,98,99," Singer Album Song categoryFilter="rock" I have filters on category and years at each level. (I may or may not have at each level) The complete list of categories and years are stored in another xml file. I need to convert this into another xml with the filters as the parent elements and everything else underneath it. Something like Year name="97" Category name="rock" Singer Album Song If I have a categoryFilter at two levels, we can assume that the parent contains a superset list of categories and if a level does not have a filter, we can assume it has the same filters as the parent. Here's an example: filters.xml <Filters> <CategoryFilters> <Category>rock</Category> <Category>pop</Category> <Category>r&b</Category> <Category>country</Category> <Category>latin</Category> </CategoryFilters> <YearsFilter> <Year>00</Year> <Year>01</Year> <Year>02</Year> <Year>03</Year> <Year>04</Year> <Year>05</Year> </YearsFilter> input.xml <Music categoryFilter="rock,pop,r&b,country,latin" yearsfilter="00,01,02,03,04,05,06" <Singer name="Shakira" categoryFilter="pop,rock,latin" yearsfilter="00,01,02,04,05,06"> <Album name="Laundry Service" yearsFilter="01" categoryFilter="latin"> <Song name="Objection (Tango)"/> <Song name="xyz"/> </Album> <Album name="Oral Fixation" yearsFilter="05,06"> <Song name="...."/> </Album> </Singer> <Singer name="Ricky Martin categoryFilter="" yearsFilter="00,04,05,06"> <Album name="I Don't Care" yearsFilter="05"> <Song name="...."/> </Album> </Singer> </Music> Expected Output: <Year name="05"> <Category name="latin"> <Singer name="Shakira"> <Album name="Oral Fixation"> <Song name="..."/> </Album> </Singer> </Category> <Year name="06"> <Category name="latin"> <Singer name="Shakira"> <Album name="Oral Fixation"> <Song name="..."/> </Album> </Singer> </Category> <Year name="01"> <Category name="latin"> <Singer name="Shakira"> <Album name="Laundry Service"> <Song name="Objection (Tango)"/> </Album> </Singer> </Category> How do I convert this ? I am new to XSLT and have gone thru' several mails and I realise I need to use grouping (for-each-group) twice, once for category and one for year. Although the structure may not make sense, I do not control the DTD for the input or the output.
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
RE: [xsl] position() inside a for x, Michael Kay | Thread | [xsl] root siblings contain xmlns=", christoph . klocker |
RE: [xsl] position() inside a for x, Michael Kay | Date | [xsl] root siblings contain xmlns=", christoph . klocker |
Month |