<xsl:stylesheet
    version="1.0" 
    exclude-result-prefixes="x ddwrt xsl msxsl slwp cmswrt" 
    xmlns:x="http://www.w3.org/2001/XMLSchema"
    xmlns:ddwrt="http://schemas.microsoft.com/WebParts/v2/DataView/runtime"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
    xmlns:msxsl="urn:schemas-microsoft-com:xslt" 
    xmlns:slwp="urn:schemas-microsoft-com:SummaryLinkWebPart"
    xmlns:cmswrt="http://schemas.microsoft.com/WebPart/v3/Publishing/runtime">
    <xsl:output method="html" indent="no" />
    <xsl:param name="slw_columnwidth" />
    <xsl:param name="slw_webpartpostback" />
    <xsl:param name="slw_iseditmode" />
    <xsl:param name="slw_isungroupedmode" />
    <xsl:param name="slw_viewemptytext" />
    <xsl:param name="slw_clientid" />
    <xsl:variable name="Group" select="'Title'" />
    <xsl:variable name="GroupType" select="''" />
    <xsl:template match="/">
        <xsl:variable name="Rows" select="/dsQueryResponse/Rows/Row" />
        <xsl:variable name="RowCount" select="count($Rows)" />
        <xsl:variable name="IsEmpty" select="$RowCount = 0" />
        <xsl:if test="$slw_iseditmode = 'True' and not($IsEmpty)">
            <xsl:text disable-output-escaping="yes">
                &lt;%@ Register Tagprefix=&quot;SharePoint&quot; Namespace=&quot;Microsoft.SharePoint.WebControls&quot; Assembly=&quot;Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c&quot; %&gt;
                &lt;SharePoint:MenuTemplate ID=&quot;SummaryLinkItemMenuTemplate&quot; runat=&quot;server&quot;&gt;
                    &lt;SharePoint:MenuItemTemplate ID=&quot;SlwpEditLink&quot; Text=&quot;</xsl:text><xsl:value-of select="cmswrt:GetPublishingResource('SummaryLinkEcbMenuItemEdit')"/><xsl:text disable-output-escaping="yes">&quot; ImageUrl=&quot;/_layouts/images/EditItem.gif&quot; ClientOnClickScript=&quot;popupAddEditLinkDialog('%mode%','%loginname%', '%sipaddress%','%title%', '%description%', '%linkurl%', '%linktooltip%', '%imageurl%', '%imagealttext%', '%group%', '%linkid%', '%groups%', '%styles%', '%style%', '%openinnewwindow%', '%postBackReference%')&quot; runat=&quot;server&quot; /&gt;
                    &lt;SharePoint:MenuItemTemplate ID=&quot;SlwpDeleteLink&quot; Text=&quot;</xsl:text><xsl:value-of select="cmswrt:GetPublishingResource('SummaryLinkEcbMenuItemDelete')"/><xsl:text disable-output-escaping="yes">&quot; ImageUrl=&quot;/_layouts/images/DelItem.gif&quot; ClientOnClickScript=&quot;deleteSummaryLink('%linkid%','%postBackReference%')&quot; runat=&quot;server&quot; /&gt;
                &lt;/SharePoint:MenuTemplate&gt;
                &lt;SharePoint:MenuTemplate ID=&quot;SummaryLinkGroupMenuTemplate&quot; runat=&quot;server&quot;&gt;
                    &lt;SharePoint:MenuItemTemplate ID=&quot;SlwpEditGroup&quot; Text=&quot;</xsl:text><xsl:value-of select="cmswrt:GetPublishingResource('SummaryLinkEcbMenuGroupEdit')"/><xsl:text disable-output-escaping="yes">&quot; ImageUrl=&quot;/_layouts/images/EditItem.gif&quot; ClientOnClickScript=&quot;popupAddEditGroupDialog('%mode%','%group%','%linkid%','%groups%','%postBackReference%')&quot; runat=&quot;server&quot; /&gt;
                    &lt;SharePoint:MenuItemTemplate ID=&quot;SlwpDeleteGroup&quot; Text=&quot;</xsl:text><xsl:value-of select="cmswrt:GetPublishingResource('SummaryLinkEcbMenuGroupDelete')"/><xsl:text disable-output-escaping="yes">&quot; ImageUrl=&quot;/_layouts/images/DelItem.gif&quot; ClientOnClickScript=&quot;deleteSummaryLinkGroup('%linkid%','%postBackReference%')&quot; runat=&quot;server&quot; /&gt;
                &lt;/SharePoint:MenuTemplate&gt;
            </xsl:text>
        </xsl:if>
        <xsl:call-template name="OuterTemplate" >
            <xsl:with-param name="Rows" select="$Rows" />
            <xsl:with-param name="FirstRow" select="1" />
            <xsl:with-param name="LastRow" select="$RowCount" />
            <xsl:with-param name="IsEmpty" select="$IsEmpty" />
        </xsl:call-template>
    </xsl:template>
    <xsl:template name="OuterTemplate">
        <xsl:param name="Rows" />
        <xsl:param name="FirstRow" />
        <xsl:param name="LastRow" />
        <xsl:param name="IsEmpty" />
      <script type="text/javascript" language="javascript">
        var slwp;
        if (slwp == null) slwp = new Array();
        slwp['<xsl:value-of select="$slw_clientid" />'] = "<xsl:value-of select="$slw_webpartpostback" />";
      </script>
        <table id="slwp_{$slw_clientid}" cellspacing="0" cellpadding="0" class="slm-layout-main">
        <tr>
            <xsl:choose>
                <xsl:when test="not($IsEmpty)">
                    <xsl:call-template name="OuterTemplate.Body">
                        <xsl:with-param name="Rows" select="$Rows" />
                        <xsl:with-param name="FirstRow" select="$FirstRow" />
                        <xsl:with-param name="LastRow" select="$LastRow" />
                    </xsl:call-template>
                </xsl:when>
                <xsl:when test="$slw_iseditmode='True'">
                    <xsl:call-template name="OuterTemplate.Empty" />
                </xsl:when>
            </xsl:choose>
        </tr>
        </table>
        <xsl:if test="$IsEmpty">
            <div>
                <xsl:call-template name="OuterTemplate.CallFooterTemplate" />
            </div>
        </xsl:if>
    </xsl:template>
    <xsl:template name="OuterTemplate.Empty">
        <td>
          <div class="wp-content description">
            <xsl:value-of select="$slw_viewemptytext" />
          </div>
        </td>
    </xsl:template>
    <xsl:template name="OuterTemplate.Body">
        <xsl:param name="Rows" />
        <xsl:param name="FirstRow" />
        <xsl:param name="LastRow" />
        <xsl:variable name="BeginColumn1" select="string('&lt;td id=&quot;column&quot; width=&quot;')" />
        <xsl:variable name="BeginColumn2" select="string('%&quot; valign=&quot;top&quot;&gt;')" />
        <xsl:variable name="BeginColumn" select="concat($BeginColumn1, $slw_columnwidth, $BeginColumn2)" />
        <xsl:variable name="EndColumn" select="string('&lt;/td &gt;')" />
        <xsl:variable name="BeginGroup" select="string('&lt;div id=&quot;group&quot; class=&quot;slm-layout-main&quot;&gt;')" />
        <xsl:variable name="EndGroup" select="string('&lt;/div&gt;')" />
        <xsl:for-each select="$Rows">
            <xsl:variable name="CurPosition" select="position()" />
            <xsl:if test="($CurPosition &gt;= $FirstRow and $CurPosition &lt;= $LastRow)">
                <xsl:variable name="StartNewGroup" select="@IsGroupHeader = 'True' or $CurPosition = $FirstRow" />
                <xsl:variable name="StartNewColumn" select="@BeginColumn = 'True'" />
                <xsl:choose>
                    <xsl:when test="$StartNewGroup and $StartNewColumn">
                        <xsl:choose>
                            <xsl:when test="$CurPosition = $FirstRow">
                                <xsl:value-of disable-output-escaping="yes" select="concat($BeginColumn, $BeginGroup)" />
                                <xsl:call-template name="OuterTemplate.CallHeaderTemplate"/>
                            </xsl:when>
                            <xsl:otherwise>
                                <xsl:call-template name="OuterTemplate.CallFooterTemplate"/>
                                <xsl:value-of disable-output-escaping="yes" select="concat($EndGroup, $EndColumn, $BeginColumn, $BeginGroup)" />
                                <xsl:call-template name="OuterTemplate.CallHeaderTemplate"/>
                            </xsl:otherwise>
                        </xsl:choose>
                    </xsl:when>
                    <xsl:when test="$StartNewGroup">
                        <xsl:call-template name="OuterTemplate.CallFooterTemplate"/>
                        <xsl:value-of disable-output-escaping="yes" select="concat($EndGroup, $BeginGroup)" />
                        <xsl:call-template name="OuterTemplate.CallHeaderTemplate"/>
                    </xsl:when>
                    <xsl:when test="$StartNewColumn">
                        <xsl:choose>
                            <xsl:when test="$CurPosition = $FirstRow">
                                <xsl:value-of disable-output-escaping="yes" select="$BeginColumn" />
                            </xsl:when>
                            <xsl:otherwise>
                                <xsl:value-of disable-output-escaping="yes" select="concat($EndColumn, $BeginColumn)" />
                            </xsl:otherwise>
                        </xsl:choose>
                    </xsl:when>
                    <xsl:otherwise>
                    </xsl:otherwise>
                </xsl:choose>
                <xsl:if test="@IsGroupHeader = 'False'">
                    <xsl:choose>
                        <xsl:when test="$slw_iseditmode = 'True'">
                            <table cellspacing="0" cellpadding="0" class="slm-layout-main">
                                <tr id="item_{@Order}">
                                    <td class="slm-edit-ecb">
                                        <div>
                                            <xsl:text disable-output-escaping="yes">
                                              &lt;%@ Register Tagprefix=&quot;PublishingWebControls&quot; Namespace=&quot;Microsoft.SharePoint.Publishing.Internal.WebControls&quot; Assembly=&quot;Microsoft.SharePoint.Publishing, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c&quot;%&gt;
                                              &lt;PublishingWebControls:SummaryLinkItemEcbMenu UseMaximumWidth=false MenuFormat=ArrowOnHover TemplateId=&quot;SummaryLinkItemMenuTemplate&quot; ItemId=&quot;</xsl:text><xsl:value-of disable-output-escaping="yes" select="@Order" /><xsl:text disable-output-escaping="yes">&quot; ImageUrl=&quot;/_layouts/images/EditItem.gif&quot; runat=&quot;server&quot;  &gt;&lt;/PublishingWebControls:SummaryLinkItemEcbMenu&gt;
                                            </xsl:text>
                                        </div>
                                    </td>
                                    <td id="dragsource" class="slm-edit-link slm-dragdrop-source">
                                        <div id="listItem">
                                            <xsl:call-template name="OuterTemplate.CallItemTemplate"/>
                                        </div>
                                    </td>
                                </tr>
                            </table>
                        </xsl:when>
                        <xsl:otherwise>
                            <xsl:call-template name="OuterTemplate.CallItemTemplate"/>
                        </xsl:otherwise>
                    </xsl:choose>
                </xsl:if>
                <xsl:if test="$CurPosition = $LastRow">
                    <xsl:call-template name="OuterTemplate.CallFooterTemplate"/>
                    <xsl:value-of disable-output-escaping="yes" select="$EndColumn" />
                </xsl:if>
            </xsl:if>
        </xsl:for-each>
    </xsl:template>
    <xsl:template name="OuterTemplate.CallHeaderTemplate">
        <xsl:choose>
            <xsl:when test="$slw_isungroupedmode = 'True'">
            </xsl:when>
            <xsl:when test="$slw_iseditmode = 'True'">
                <table cellspacing="0" cellpadding="0" class="slm-layout-main">
                    <tr>
                        <td class="slm-edit-ecb">
                            <xsl:text disable-output-escaping="yes">
                                &lt;%@ Register Tagprefix=&quot;PublishingWebControls&quot; Namespace=&quot;Microsoft.SharePoint.Publishing.Internal.WebControls&quot; Assembly=&quot;Microsoft.SharePoint.Publishing, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c&quot;%&gt;
                                &lt;PublishingWebControls:SummaryLinkGroupEcbMenu UseMaximumWidth=false MenuFormat=ArrowOnHover TemplateId=&quot;SummaryLinkGroupMenuTemplate&quot; ItemId=&quot;</xsl:text><xsl:value-of disable-output-escaping="yes" select="@Order" /><xsl:text disable-output-escaping="yes">&quot; ImageUrl=&quot;/_layouts/images/EditItem.gif&quot; runat=&quot;server&quot;  &gt;&lt;/PublishingWebControls:SummaryLinkGroupEcbMenu&gt;
                            </xsl:text>
                        </td>
                        <td id="dragsource" class="slm-edit-link slm-dragdrop-source">
                            <div id="header" group="{@Title}">
                                <xsl:apply-templates select="." mode="header">
                                </xsl:apply-templates>
                            </div>
                        </td>
                    </tr>
                </table>
            </xsl:when>
            <xsl:otherwise>
                <xsl:apply-templates select="." mode="header">
                </xsl:apply-templates>
            </xsl:otherwise>
        </xsl:choose>
    </xsl:template>
    <xsl:template name="OuterTemplate.CallItemTemplate">
        <xsl:apply-templates select="." mode="itemstyle">
        </xsl:apply-templates>
    </xsl:template>
    <xsl:template name="OuterTemplate.CallFooterTemplate">
        <div id="footer">
        </div>
    </xsl:template>
    <xsl:template name="OuterTemplate.CallPresenceStatusIconTemplate">
        <xsl:variable name="prefix">IMNRC('</xsl:variable>
        <xsl:variable name="suffix">')</xsl:variable>
        <xsl:variable name="id" select="@Order"/>        
        <xsl:if test="string-length(@SipAddress) != 0">
            <span class="presence-status-icon">
                <img src="/_layouts/images/imnhdr.gif" onload="{concat($prefix, @SipAddress, $suffix)}" ShowOfflinePawn="1" id="{concat('MWP_pawn_',$slw_clientid,'_',$id,',type=sip')}"/>
            </span>
        </xsl:if>
    </xsl:template>
    <xsl:template name="OuterTemplate.GetGroupName">
        <xsl:param name="GroupName"/>
        <xsl:param name="GroupType"/>
        <xsl:choose>
            <xsl:when test="string-length(normalize-space($GroupName)) = 0">
                <br/>
            </xsl:when>
            <xsl:otherwise>
                <xsl:value-of select="$GroupName" />
            </xsl:otherwise>
        </xsl:choose>
    </xsl:template>
    <xsl:template name="OuterTemplate.GetTitle">
        <xsl:param name="Title"/>
        <xsl:value-of select="$Title"/>
    </xsl:template>
    <xsl:template name="OuterTemplate.GetSafeLink">
        <xsl:param name="UrlColumnName"/>
        <xsl:call-template name="OuterTemplate.GetSafeStaticUrl">
            <xsl:with-param name="UrlColumnName" select="$UrlColumnName"/>
        </xsl:call-template>
    </xsl:template>
    <xsl:template name="OuterTemplate.GetSafeStaticUrl">
        <xsl:param name="UrlColumnName"/>
        <xsl:value-of select="@*[name()=$UrlColumnName]"/>
    </xsl:template>
    <xsl:template name="OuterTemplate.GetColumnDataForUnescapedOutput">
    </xsl:template>
  </xsl:stylesheet>
