I have created a tabbed jquery ui content query webpart with xsl below. My issue as shown in the image is the tabs are repeating itself when the same value is selected twice. I just want one tab value with all docs grouped under it. Any help greatly appreciated please.
<xsl:template name="Content" match="Row[@Style='Content']" mode="itemstyle">
<xsl:param name="CurPosition"/>
<xsl:param name="LastRow"/>
<xsl:param name="Today" />
<xsl:variable name="myID" select="@ID"/>
<!--If you set 'totalPositions' to a fixed value, only that number of items will display -->
<xsl:variable name="totalPositions" select="count(../Row[@Style='Content'])"/>
<xsl:variable name="myPosition">
<xsl:for-each select="../Row[@Style='Content']">
<xsl:if test="position() <= $totalPositions">
<xsl:if test="@ID=$myID">
<xsl:value-of select="position()"/>
</xsl:if>
</xsl:if>
</xsl:for-each>
</xsl:variable>
<xsl:variable name="RowNum" select="count(./preceding-sibling::*)" />
<xsl:variable name="Rows" select="/dsQueryResponse/Rows/Row" />
<xsl:variable name="myNumber">
<xsl:value-of select="substring-before(substring-after($PageUrl,'Location='),'and')" disable-output-escaping="yes" />
</xsl:variable>
<xsl:variable name="tabheader">
<xsl:choose>
<xsl:when test="contains($PageUrl,'Departments=')" >
<xsl:value-of select="substring-after($PageUrl,'Departments=')" disable-output-escaping="yes" />
</xsl:when>
</xsl:choose>
</xsl:variable>
<xsl:variable name="myLocation" select="@Categories"></xsl:variable>
<xsl:variable name="LocationNum" select="count(preceding-sibling::*[@*['Categories']=$myLocation])"/>
<xsl:variable name="myLocationName">
<xsl:if test="$LocationNum <1">
<xsl:value-of select="@Categories" disable-output-escaping="yes"></xsl:value-of>
</xsl:if>
</xsl:variable>
<xsl:variable name="tabPosition" select="position()"/>
<xsl:variable name="SafeLinkUrl">
<xsl:call-template name="OuterTemplate.GetSafeLink">
<xsl:with-param name="UrlColumnName" select="'LinkUrl'"/>
</xsl:call-template>
</xsl:variable>
<xsl:variable name="SafeImageUrl">
<xsl:call-template name="OuterTemplate.GetSafeStaticUrl">
<xsl:with-param name="UrlColumnName" select="'Url'"/>
</xsl:call-template>
</xsl:variable>
<xsl:variable name="SafeImageHtml">
<xsl:call-template name="OuterTemplate.GetColumnDataForUnescapedOutput">
<xsl:with-param name="Name" select="'Image'" />
<xsl:with-param name="MustBeOfType" select="'Image'" />
<xsl:with-param name="PublishingPageImage" select="'Image'" />
</xsl:call-template>
</xsl:variable>
<xsl:variable name="DisplayTitle">
<xsl:call-template name="OuterTemplate.GetTitle">
<xsl:with-param name="Title" select="@Title"/>
<xsl:with-param name="UrlColumnName" select="'LinkUrl'"/>
</xsl:call-template>
</xsl:variable>
<xsl:variable name="Path">
<xsl:call-template name="substring-before-last">
<xsl:with-param name="TargetString" select="$PageUrl"/>
<xsl:with-param name="Token" select="'/'"/>
</xsl:call-template>
</xsl:variable>
<xsl:variable name="LinkTarget">
<xsl:if test="@OpenInNewWindow = 'True'">_blank</xsl:if>
</xsl:variable>
<xsl:if test="count(preceding-sibling::*)=0">
<xsl:text disable-output-escaping="yes"><![CDATA[
<html>
<head>
<script type="text/javascript" src="/js/jquery-ui-1.10.0.custom.min.js"></script>
<link rel="stylesheet" href="/css/jquery-ui-1.10.0.custom.min.css" type="text/css" />
<script type="text/javascript">
$(function() {
$('#Tabs').tabs();
});
</script>
</head>
<body>
<div id="Tabs">
]]></xsl:text>
<!--Beginning of Tabs-->
<xsl:text disable-output-escaping="yes"><![CDATA[<ul>]]></xsl:text>
<xsl:for-each select="$Rows">
<xsl:sort select="@Categories" order="ascending" ></xsl:sort>
<xsl:if test="@Categories!= ''">
<xsl:choose>
<xsl:when test="@Departments = $tabheader and @Location=$myNumber">
<li>
<a href="{concat('#tabs-',@ID)}">
<xsl:value-of select="@Categories" disable-output-escaping="yes"></xsl:value-of>
<xsl:value-of select="$myLocationName" disable-output-escaping="yes"/>
</a>
</li>
</xsl:when>
</xsl:choose>
</xsl:if>
</xsl:for-each>
<xsl:text disable-output-escaping="yes"><![CDATA[</ul>]]></xsl:text>
<!--End of Tabs>-->
<xsl:for-each select="$Rows">
<!--Beginning of Content-->
<xsl:choose>
<xsl:when test="contains($PageUrl,concat('Location=',@Location,'and','Departments=',@Departments))" >
<ul>
<li style="font-size:12px;font-weight:bold; padding-left:3px;">
<xsl:value-of select="@SubCategory" disable-output-escaping="yes"></xsl:value-of>
</li>
</ul>
</xsl:when>
</xsl:choose>
<div id="{concat('tabs-',@ID)}">
<ul>
<xsl:choose>
<xsl:when test="contains($PageUrl,concat('Location=',@Location,'and','Departments=',@Departments))" >
<xsl:if test="@Location != '' and @Departments != ''">
<li>
<xsl:value-of select="@FileLeafRef" disable-output-escaping="yes" />
<span >
<xsl:value-of select="ddwrt:FormatDate(string(@Created) ,2057 ,5)"/>
</span>
</li>
<!-- </xsl:if>-->
</xsl:if>
</xsl:when>
</xsl:choose>
</ul>
</div>
<!--End of Content-->
</xsl:for-each>
<xsl:text disable-output-escaping="yes"><![CDATA[</div></body></html>]]></xsl:text>
</xsl:if>
</xsl:template>