I want to write some code to group based on TITLE within its each separate CATALOG tag. I am using XSLT 1.0 version.
<?xml version="1.0" encoding="UTF-8"?>
<hello>
<catalog>
<cd>
<title>Empire Burlesque</title>
<artist>Bob Dylan</artist>
<country>USA</country>
<company>Columbia</company>
<price>10.90</price>
<year>1985</year>
</cd>
<cd>
<title>Empire Burlesque</title>
<artist>Bob Dylan</artist>
<country>USA</country>
<company>Columbia</company>
<price>10.90</price>
<year>2000</year>
</cd>
<cd>
<title>Unchain my heart</title>
<artist>Joe Cocker</artist>
<country>USA</country>
<company>EMI</company>
<price>8.20</price>
<year>1987</year>
</cd>
</catalog>
<catalog>
<cd>
<title>Ring My Bells</title>
<artist>Enrique</artist>
<country>USA</country>
<company>EMI</company>
<price>8.20</price>
<year>1987</year>
</cd>
<cd>
<title>Empire Burlesque</title>
<artist>Bob Dylan</artist>
<country>USA</country>
<company>Columbia</company>
<price>10.90</price>
<year>1985</year>
</cd>
</catalog>
</hello>
Expected output:
<Song>
<Desc>From First Catalog</Desc>
<nameofAlbum>Empire Burlesque</nameofAlbum>
<nameofAlbum>Unchain my heart</nameofAlbum>
</Song>
<Song>
<Desc>From Second Catalog</Desc>
<nameofAlbum>Ring My Bells</nameofAlbum>
<nameofAlbum>Empire Burlesque</nameofAlbum>
</Song>
The requirement is to group based on title of each CatLog only.
I have tried using the Muenchian grouping but it was grouping with all the catalogs tags where as I require as induvial grouping between catalogs.
Since you want to dedup within the
catalog, I would usegenerate-id()and create a composite key with the generated ID for the catalog element and thecd/title.Use that composite key for the
xsl:keymatching oncd, then you can iterate over each/hello/catalogand then for eachcdunder thatcatalogyou can use the key for Muenchian grouping: