Several options are available for this purpose:
OOTB WebPartId
parameter for CQWP
This parameter allows to identify instance of CQWP on page.
Pros: No code solution
Cons: Not appropriate for deployment scenarios (web part id is generated during creation of CQWP instance)
For example:
<xsl:choose>
<xsl:when test="$WebPartId = 'c7636893-cd8b-4d85-b8e7-f9659d149ce3'">
<!-- Specific CQWP processing goes here -->
</xsl:when>
<xsl:otherwise>
<!-- Another CQWP processing goes here -->
</xsl:otherwise>
</xsl:choose>
Extend (subclass) CQWP
public class ContentByQueryWebPartEx : ContentByQueryWebPart
{
protected override void ModifyXsltArgumentList(ArgumentClassWrapper argList)
{
argList.AddParameter("cbq_instanceId", string.Empty, CBQInstanceId);
base.ModifyXsltArgumentList(argList);
}
/// <summary>
/// Return the tool panes that configure this <see cref="T:Microsoft.SharePoint.Publishing.WebControls.ContentByQueryWebPart"/> object..
/// </summary>
[SharePointPermission(SecurityAction.Demand, ObjectModel = true)]
public override ToolPart[] GetToolParts()
{
return new ToolPart[3]
{
new ContentByQueryToolPart(),
new WebPartToolPart(),
new CBQToolPart() //Custom Tool Part
};
}
#endregion
[Personalizable(PersonalizationScope.Shared),WebBrowsable(true)]
public string CBQInstanceId { get; set; }
#endregion
}
After referencing it XSLT
<xsl:param name="cbq_instanceId" />
it could be used in XPath queries
Pros: Web part instance parameter could be specified during deployment process
Cons: Implementation is required
Extend (subclass) CQWP with parameter binding
public class ContentByQueryWebPartEx : ContentByQueryWebPart
{
/// <summary>
/// Return the tool panes that configure this <see cref="T:Microsoft.SharePoint.Publishing.WebControls.ContentByQueryWebPart"/> object..
/// </summary>
[SharePointPermission(SecurityAction.Demand, ObjectModel = true)]
public override ToolPart[] GetToolParts()
{
return new ToolPart[3]
{
new ContentByQueryToolPart(),
new WebPartToolPart(),
new CBQToolPart() //Custom Tool Part
};
}
#endregion
[Personalizable(PersonalizationScope.Shared),WebBrowsable(true)]
public string CBQInstanceId { get; set; }
#endregion
}
After specifying ParameterBindings property in web part
<ParameterBinding Name="cbq_instanceId" Location="WPProperty(CBQInstanceId)" />
and referencing it XSLT
<xsl:param name="cbq_instanceId" />
it could be used in XPath queries:
<xsl:choose>
<xsl:when test="$cbq_instanceId = 'ABC'">
<!-- Specific CQWP processing goes here -->
</xsl:when>
<xsl:otherwise>
<!-- Another CQWP processing goes here -->
</xsl:otherwise>
</xsl:choose>
Pros: Web part instance parameter could be specified during deployment process, no code solution
Cons: Implementation for custom properties is required