xslt subgroups of groups without duplicates

Dorlovesjonas

New Member
after about 3 hours of tinkers with xslt,I have the following output\[code\] <?xml version="1.0" encoding="UTF-8"?><tops><topCategory name="cat1"> <top name="ninja" tuckedIn="0"> <part path="ninja_abdomen.png" bodyPart="abdomen"/> <part path="ninja_humerus_l.png" bodyPart="humerus_l"/> </top> <top name="ninja" tuckedIn="0"> <part path="ninja_abdomen.png" bodyPart="abdomen"/> <part path="ninja_humerus_l.png" bodyPart="humerus_l"/> </top> <top name="pirate" tuckedIn="0"> <part path="pirate_humerus_l.png" bodyPart="humerus_l"/> </top></topCategory><topCategory name="cat2"> <top name="monk" tuckedIn="1"> <part path="monk_head.png" bodyPart="head"/> </top> <top name="monkey" tuckedIn="1"> <part path="monkey_thorax.png" bodyPart="thorax"/> <part path="monkey_neck.png" bodyPart="neck"/> </top> <top name="monkey" tuckedIn="1"> <part path="monkey_thorax.png" bodyPart="thorax"/> <part path="monkey_neck.png" bodyPart="neck"/> </top></topCategory></tops>\[/code\]The problem is that I have duplicate s I would only like to have one entry of s for each name. I believe I am very close to the solution, but cant quite figure it out.the original xml file\[code\]<?xml version="1.0" encoding="UTF-8" standalone="yes"?><tops> <top path = "ninja_abdomen.png" bodyPart = "abdomen" name = "ninja" tuckedIn = "0" topCategory= "cat1"/> <top path = "ninja_humerus_l.png" bodyPart = "humerus_l" name = "ninja" tuckedIn = "0" topCategory= "cat1"/> <top path = "pirate_humerus_l.png" bodyPart = "humerus_l" name = "pirate" tuckedIn = "0" topCategory= "cat1"/> <top path="monk_head.png" bodyPart="head" name="monk" tuckedIn="1" topCategory="cat2"/> <top path="monkey_thorax.png" bodyPart="thorax" name="monkey" tuckedIn="1" topCategory="cat2"/> <top path="monkey_neck.png" bodyPart="neck" name="monkey" tuckedIn="1" topCategory="cat2"/></tops>\[/code\]and xslt file\[code\]<?xml version="1.0" encoding="UTF-8"?><xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"><xsl:output method="xml" indent = "yes"/><xsl:key name="eachTopCategory" match="tops/top" use="@topCategory"/><xsl:key name="eachTopName" match="tops/top" use="@name"/><xsl:key name="eachTop" match="tops/top" use="concat(@topCategory,'|', @name)"/><xsl:key name="eachPart" match="tops/top" use="concat(@bodyPart,'|' ,@name,'|',@topCategory)"/><xsl:template match="tops"> <tops> <xsl:apply-templates select="top[generate-id(.)=generate-id(key('eachTopCategory',@topCategory)[1])]"/> </tops></xsl:template><xsl:template match="top"> <topCategory> <xsl:attribute name="name"> <xsl:value-of select="@topCategory" /> </xsl:attribute> <xsl:for-each select="key('eachTopCategory',@topCategory)"> <xsl:call-template name="sortTops"/> </xsl:for-each> </topCategory></xsl:template><xsl:template name="sortTops"> <top> <xsl:attribute name="name"> <xsl:value-of select="@name" /> </xsl:attribute> <xsl:attribute name="tuckedIn"> <xsl:value-of select="@tuckedIn" /> </xsl:attribute> <xsl:for-each select="key('eachTop', concat(@topCategory,'|', @name))"> <xsl:call-template name="sortParts"/> </xsl:for-each> </top></xsl:template><xsl:template name="sortParts"> <part> <xsl:attribute name="path"> <xsl:value-of select="@path" /> </xsl:attribute> <xsl:attribute name="bodyPart"> <xsl:value-of select="@bodyPart" /> </xsl:attribute> </part></xsl:template></xsl:stylesheet>\[/code\]
 
Back
Top