CQWP: 30 Tips #8 Updates and Comments

I don’t shy away from injecting my custom logic into the OOTB templates.  See Tip #7 where I updated the template that generates the group header display text (http://www.intranoggin.com/2012/02/1052/).

However, there almost always comes a time later on where you’ll want to see just what the heck the original code did, or you’ll find yourself looking back at an OOTB template and wondering if it came that way or if it was customized at some point.  To make my life easier, I’ve adopted this workflow.

First off, never make changes to the OOTB .xsl sheets.  Always make a copy and point your CQWP’s .dwp at your copies.  I covered this in Tip #1 (http://www.intranoggin.com/2012/02/1042/). 

Second, in those .xsl copies, if you want to update the logic of an OOTB template, comment out the original template version, then make a copy that contains the original with your changes.  I usually leave the commented version right in its original location and put my modified version at the end of the file.

If you didn’t know, comments in .xsl are anything that begins with <!– and ends with –>

As an example, the modified section of .xsl from Tip #7 resides in a file called Custom_ContentQueryMain.xsl and looks like this:

 

<!--xsl:template name="OuterTemplate.GetGroupName">
        <xsl:param name="GroupName"/>
        <xsl:param name="GroupType"/>
        <xsl:choose>
            <xsl:when test="string-length(normalize-space($GroupName)) = 0">
                <xsl:value-of select="$BlankGroup"/>
            </xsl:when>
            <xsl:otherwise>
                <xsl:choose>
                    <xsl:when test="$GroupType='URL'">
                        <xsl:variable name="Url">
                            <xsl:call-template name="OuterTemplate.FormatValueIntoUrl">
                                <xsl:with-param name="Value" select="$GroupName"/>
                            </xsl:call-template>
                        </xsl:variable>
                        <xsl:call-template name="OuterTemplate.GetPageNameFromUrlRecursive">
                            <xsl:with-param name="Url" select="$Url"/>
                        </xsl:call-template>
                    </xsl:when>
                    <xsl:otherwise>
                        <xsl:value-of select="$GroupName" />
                    </xsl:otherwise>
                </xsl:choose>
            </xsl:otherwise>
        </xsl:choose>
    </xsl:template-->
    <xsl:template name="OuterTemplate.CallPresenceStatusIconTemplate">
        <xsl:if test="string-length(@SipAddress) != 0">
            <span class="presence-status-icon">
                <img src="/_layouts/images/imnhdr.gif" onload="IMNRC('{@SipAddress}')" ShowOfflinePawn="1" alt="" id="{concat('MWP_pawn_',$ClientId,'_',@ID,'type=sip')}"/>
            </span>
        </xsl:if>
    </xsl:template>
    <xsl:template name="OuterTemplate.GetFileNameWithoutExtension">
        <xsl:param name="input"/>
        <xsl:variable name="extension">
          <xsl:value-of select="substring-after($input, '.')"/>
        </xsl:variable>
        <xsl:choose>
            <xsl:when test="contains($extension, '.')">
                <xsl:variable name="afterextension">
              <xsl:call-template name="OuterTemplate.GetFileNameWithoutExtension">
                <xsl:with-param name="input" select="$extension"/>
              </xsl:call-template>
            </xsl:variable>
                <xsl:value-of select="concat(substring-before($input, '.'), $afterextension)"/>
            </xsl:when>
            <xsl:otherwise>
                <xsl:choose>
                    <xsl:when test="contains($input, '.')">
                        <xsl:value-of select="substring-before($input, '.')"/>
                    </xsl:when>
                    <xsl:otherwise>
                        <xsl:value-of select="$input"/>
                    </xsl:otherwise>
                </xsl:choose>
            </xsl:otherwise>
        </xsl:choose>
    </xsl:template>
    <!--Begin Overrides and Custom Templates-->
    <xsl:template name="OuterTemplate.GetGroupName">
        <xsl:param name="GroupName"/>
        <xsl:param name="GroupType"/>
        <xsl:choose>
            <xsl:when test="string-length(normalize-space($GroupName)) = 0">
                <xsl:value-of select="$BlankGroup"/>
            </xsl:when>
            <xsl:otherwise>
                <xsl:choose>
                    <xsl:when test="$GroupType='URL'">
                        <xsl:variable name="Url">
                            <xsl:call-template name="OuterTemplate.FormatValueIntoUrl">
                                <xsl:with-param name="Value" select="$GroupName"/>
                            </xsl:call-template>
                        </xsl:variable>
                        <xsl:call-template name="OuterTemplate.GetPageNameFromUrlRecursive">
                            <xsl:with-param name="Url" select="$Url"/>
                        </xsl:call-template>
                    </xsl:when>
                    <xsl:otherwise>
                        <xsl:call-template name="OuterTemplate.RemovePrependedOrderDigits">
                            <xsl:with-param name="GroupName" select="$GroupName"/>
                        </xsl:call-template>
                    </xsl:otherwise>
                </xsl:choose>
            </xsl:otherwise>
        </xsl:choose>
    </xsl:template>
    <xsl:template name="OuterTemplate.RemovePrependedOrderDigits">
        <xsl:param name="GroupName"/>
        <xsl:choose>
            <xsl:when test="contains($GroupName,'_')">
                <xsl:variable name="OrderBits">
                    <xsl:value-of select="substring-before($GroupName,'_')"/>
                </xsl:variable>
                <xsl:choose>
                    <xsl:when test="translate($OrderBits,'0123456789','') = ''">
                        <xsl:value-of select="substring-after($GroupName,'_')"/>
                    </xsl:when>
                    <xsl:otherwise>
                        <xsl:value-of select="$GroupName"/>
                    </xsl:otherwise>
                </xsl:choose>
            </xsl:when>
            <xsl:otherwise>
                <xsl:value-of select="$GroupName"/>
            </xsl:otherwise>
        </xsl:choose>
    </xsl:template>
Share:
  • Print
  • Digg
  • StumbleUpon
  • del.icio.us
  • Facebook
  • Yahoo! Buzz
  • Twitter
  • Google Bookmarks
  • LinkedIn
  • Reddit
  • RSS
  • Google Buzz
  • Tumblr

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>