In this case, the best fit was to add a new check to the QA plugin.
The check should:
• Identify duplicate @id values on specific elements
• Return only distinct values (i.e. if 123 appears several times, then return 123 only once)
After some forum research, my first thought was to use a key match.
<xsl:key name="duplicateIds" match="elementName" use="@id" />
And reference it with
key('duplicateIds',@id) and count(.|key('duplicateIds', @id)) = 1
So the if statement for the check looked like
<xsl:for-each select="//parentElement"> <xsl:if test="key('duplicateIds',@id) and count(.|key('duplicateIds', @id)) = 1"> Remove duplicate elementName @id=<xsl:value-of select="@id"/> </xsl:if> </xsl:for-each>
Even though it met my requirements, it’s still an outdated approach that didn’t leave me with a job-well-done sense of completion. I wanted a cleaner solution that fit somewhere closer to the 2.0 realm.
I decided to use grouping to identify each distinct @id value. Then I could wrap an if statement to test for any groups that contained a second (duplicate) item. The result:
<xsl:for-each-group select="//elementName" group-by="@id"> <xsl:if test="current-group()"> Remove duplicate elementName @id=<xsl:value-of select="@id"/> </xsl:if> </xsl:for-each-group>
Have a better approach? Leave a comment.