Yes, this is another XSLT grouping/duplicates questions, but I was unable to find any answers that I could successfully apply to my situation.
This is the original XML:
<data jsxid="jsxroot">
<record jsxid="10" groupNum="1319" item="q123" total="1"/>
<record jsxid="20" groupNum="1319" item="w123" total="1"/>
<record jsxid="30" groupNum="1319" item="" total="0"/>
<record jsxid="40" groupNum="1322" item="z123" total="1"/>
<record jsxid="50" groupNum="1322" item="x123" total="1"/>
<record jsxid="60" groupNum="1322" item="c123" total="1"/>
<record jsxid="70" groupNum="1322" item="" total="0"/>
<record jsxid="80" groupNum="1323" item="x123" total="1"/>
<record jsxid="90" groupNum="1323" item="c123" total="1"/>
<record jsxid="100" groupNum="1323" item="z123" total="1"/>
<record jsxid="110" groupNum="1323" item="" total="0"/>
</data>
First, I need it grouped by attribute "groupNum" and wrapped in a parent element jsxid that increments with each group, so that the output looks like this:
<data jsxid="jsxroot">
<record jsxid="1">
<record jsxid="10" groupNum="1319" item="q123" total="1"/>
<record jsxid="20" groupNum="1319" item="w123" total="1"/>
<record jsxid="30" groupNum="1319" item="" total="0"/>
</record>
<record jsxid="2">
<record jsxid="40" groupNum="1322" item="z123" total="1"/>
<record jsxid="50" groupNum="1322" item="x123" total="1"/>
<record jsxid="60" groupNum="1322" item="c123" total="1"/>
<record jsxid="70" groupNum="1322" item="" total="0"/>
</record>
<record jsxid="3">
<record jsxid="80" groupNum="1323" item="x123" total="1"/>
<record jsxid="90" groupNum="1323" item="c123" total="1"/>
<record jsxid="100" groupNum="1323" item="z123" total="1"/>
<record jsxid="110" groupNum="1323" item="" total="0"/>
</record>
</data>
I was able to accomplish that with this stylesheet:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes" />
<xsl:key name="groupNum" match="data/*" use="@groupNum" />
<xsl:template match="data">
<data>
<xsl:apply-templates select="*[generate-id(.)=generate-id(key('groupNum',@groupNum)[1])]"/>
</data>
</xsl:template>
<xsl:template match="*">
<record jsxid="{position()}" >
<xsl:copy-of select="key('groupNum', @groupNum)" />
</record>
</xsl:template>
</xsl:stylesheet>
Now I need to remove any grouping that contains the exact same items as another grouping for records where total = "1". If you look at the groupings of jsxid = 2 and jsxid = 3 above, you'll see that they both contain the following item attributes, though not in the same order:
item="x123"
item="c123"
item="z123"
So I want to remove the entire jsxid = 3 grouping and have the final output look like this:
<data jsxid="jsxroot">
<record jsxid="1">
<record jsxid="1" groupNum="1319" item="q123" total="1"/>
<record jsxid="2" groupNum="1319" item="w123" total="1"/>
<record jsxid="3" groupNum="1319" item="" total="0"/>
</record>
<record jsxid="2">
<record jsxid="4" groupNum="1322" item="z123" total="1"/>
<record jsxid="5" groupNum="1322" item="x123" total="1"/>
<record jsxid="6" groupNum="1322" item="c123" total="1"/>
<record jsxid="7" groupNum="1322" item="" total="0"/>
</record>
</data>
EDIT: Instead of removing the duplicate grouping, what if I wanted to add in a new attribute as a "grouping identifier." I'd call it something like "groupType" so the output for the above situation where the last two groupings are the same, they would have the same grouptype:
<data jsxid="jsxroot">
<record jsxid="1">
<record jsxid="10" groupNum="1319" item="q123" groupType = "type1" total="1"/>
<record jsxid="20" groupNum="1319" item="w123" groupType = "type1" total="1"/>
<record jsxid="30" groupNum="1319" item="" groupType = "type1" total="0"/>
</record>
<record jsxid="2">
<record jsxid="40" groupNum="1322" item="z123" groupType = "type2" total="1"/>
<record jsxid="50" groupNum="1322" item="x123" groupType = "type2" total="1"/>
<record jsxid="60" groupNum="1322" item="c123" groupType = "type2" total="1"/>
<record jsxid="70" groupNum="1322" item="" groupType = "type2" total="0"/>
</record>
<record jsxid="3">
<record jsxid="80" groupNum="1323" item="x123" groupType = "type2" total="1"/>
<record jsxid="90" groupNum="1323" item="c123" groupType = "type2" total="1"/>
<record jsxid="100" groupNum="1323" item="z123" groupType = "type2" total="1"/>
<record jsxid="110" groupNum="1323" item="" groupType = "type2" total="0"/>
</record>
</data>
Any help is greatly appreciated.