Wednesday, August 26, 2009

itemstyle.xsl or using own testing style

So you want to make your webpart display in own style, well once you point your webpart to own file you need to create that file.


<xsl:template name="Testing" match="Row[@Style='Testing']" mode="itemstyle">
  <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="'ImageUrl'" /></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="LinkTarget"><xsl:if test="@OpenInNewWindow = 'True'">_blank</xsl:if></xsl:variable>
  <div id="linkitem" class="item">
   <xsl:if test="string-length($SafeImageUrl) != 0">
    <div class="image-area-left">
     <a href="{$SafeLinkUrl}" target="{$LinkTarget}">
      <img class="image" src="{$SafeImageUrl}" alt="{@ImageUrlAltText}" />
     </a>
    </div>
   </xsl:if>
   <div class="link-item">
    <xsl:call-template name="OuterTemplate.CallPresenceStatusIconTemplate" />
    <a href="{$SafeLinkUrl}" target="{$LinkTarget}" title="{@LinkToolTip}">
     <xsl:value-of select="$DisplayTitle" />
    </a>
    <div class="description">
     <xsl:value-of select="@Description" />
     <xsl:for-each select="@*">
     P:<xsl:value-of select="name()" />(<xsl:value-of select="."/>)
    </xsl:for-each>
    </div>
   </div>
  </div>
 </xsl:template>
 



This I save in the same place as ItemStyle.xsl and call Internet.xsl, it has a default style (from itemstyle.xsl) so when switch to using it won't break the webpart. Then it has a testing style that allows me to see if the "CommonFields" I added are working and show correct value.

From the testing I can then create a new style to display those fields how I want.

Within my next posts I'll explain more on XSL; I have found this to be great once I understood what it can do...

No comments:

Post a Comment