Showing posts with label XSL. Show all posts
Showing posts with label XSL. Show all posts

Tuesday, July 26, 2011

XSL Date using ddwrt Namespace

The following comes from: http://msdn.microsoft.com/en-us/library/dd583143(v=office.11).aspx

XSL Date using ddwrt Namespace... NOTE: Ensure the xsl stylesheet includes a reference to ddwrt ... Eg:

<xsl:stylesheet xmlns:x="http://www.w3.org/2001/XMLSchema" xmlns:d="http://schemas.microsoft.com/sharepoint/dsp" version="1.0" exclude-result-prefixes="xsl msxsl ddwrt" xmlns:ddwrt="http://schemas.microsoft.com/WebParts/v2/DataView/runtime" xmlns:asp="http://schemas.microsoft.com/ASPNET/20" xmlns:__designer="http://schemas.microsoft.com/WebParts/v2/DataView/designer" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt" xmlns:SharePoint="Microsoft.SharePoint.WebControls" xmlns:ddwrt2="urn:frontpage:internal" xmlns:o="urn:schemas-microsoft-com:office:office">

Functions:

public string FormatDate(string szDate, long lcid, long formatFlag);
<xsl:value-of select="ddwrt:FormatDateTime(ddwrt:TodayIso(),2057,'dddd MMMM dd yyyy')" />

public string TodayIso();
<xsl:value-of select="ddwrt:TodayIso()"/>

public string Today();
<xsl:value-of select="ddwrt:Today()"/>

  • Date only as M/d/yyyy. Example: "08/17/2000".
  • Date only as dddd, MM dd, yyyy. Example: "Thursday, August 17, 2000".
  • Time only as h:mm. Example: "16:32".
  • DateTime as M/d/yyyy h:mm. Example: "08/17/2000 16:32".
  • DateTime as dddd, MM dd, yyyy h:mm. Example: "Thursday, August 17, 2000 16:32".
  • Time only as h:mm:ss. Example: "16:32:32".
  • DateTime as M/d/yyyy h:mm:ss. Example: "08/17/2000 16:32:32".
  • DateTime as dddd, MMMM dd, yyyy h:mm:ss. Example: "Thursday, August 17, 2000 16:32:32".

    Wednesday, July 06, 2011

    XLV Web Parts

    To display an XLV on another site update the Title, Description, ListId and WebId values in this code; save as a .webpart; upload the file to a web part page (more info on Glyn's blog):

    <?xml version="1.0" encoding="utf-8" ?>
    <webParts>
    <webPart xmlns="http://schemas.microsoft.com/WebPart/v3">
    <metaData>
    <type name="Microsoft.SharePoint.WebPartPages.XsltListViewWebPart, Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" />
    <importErrorMessage>Cannot import this Web Part.</importErrorMessage>
    </metaData>
    <data>
    <properties>
    <property name="Title" type="string">My List</property>
    <property name="Description" type="string">A view of My list from the root of the site</property>
    <property name="ListName" type="string">8480D028-A2ED-474B-8259-BEE394EE4C53</property>
    <property name="ListId" type="System.Guid, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">8480D028-A2ED-474B-8259-BEE394EE4C53</property>
    <property name="WebId" type="System.Guid, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">adea17f7-e661-4ff0-91e9-70f021c60647</property>
    <property name="ExportMode" type="exportmode">All</property>
    </properties>
    </data>
    </webPart>
    </webParts>

    Wednesday, June 01, 2011

    Return all values in XSL

    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" >
    <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes" />
    <xsl:template match="/">
    <xmp><xsl:copy-of select="*"/></xmp>
    </xsl:template>
    </xsl:stylesheet>

    Contextual Search Results

    I wanted to configure a contextual search to bring back results from a particular list only and display the results on the same web part page. I also wanted to be able to open the results items in a modal dialogue box (new for SharePoint 2010). On my page I have:
    1. a Search Box web part configured as follows: 
      • Scopes dropdown: Do not show dropdown and default to target results page 
    2. a Search Core Results web part configured as follows: 
      • Results Query options / Append Text To Query - Site:http://site/Lists/ListName contentclass:STS_ListItem.
      • Edit the Display Properties XSL by searching for this line:

        <xsl:attribute name="href"> <xsl:value-of  select="$url"> </xsl:value-of></xsl:attribute>

        and replacing it with this:

        <xsl:attribute name="href"> javascript:OpenDialog('<xsl:value-of select="$url">') </xsl:value-of></xsl:attribute>
      Thanks to Glyn for pointing me in the right direction again and Rain Tree Studio for this list of contentclass values, which can be appended to a search query:

              case "STS_Web":                                       // Site
              case "STS_List_850":                                 // Page Library
              case "STS_ListItem_850":                          // Page
              case "STS_List_DocumentLibrary":            // Document Library
              case "STS_ListItem_DocumentLibrary":     // Document Library Items
              case "STS_List":                                        // Custom List
              case "STS_ListItem":                                 // Custom List Item
              case "STS_List_Links":                             // Links List
              case "STS_ListItem_Links":                      // Links List Item
              case "STS_List_Tasks":                            // Tasks List
              case "STS_ListItem_Tasks":                     // Tasks List Item
              case "STS_List_Events":                          // Events List
              case "STS_ListItem_Events":                   // Events List Item
              case "STS_List_Announcements":            // Announcements List
              case "STS_ListItem_Announcements":     // Announcements List Item
              case "STS_List_Contacts":                      // Contacts List
              case "STS_ListItem_Contacts":               // Contacts List Item
              case "STS_List_DiscussionBoard":          // Discussion List
              case "STS_ListItem_DiscussionBoard":   // Discussion List Item
              case "STS_List_IssueTracking":              // Issue Tracking List
              case "STS_ListItem_IssueTracking":       // Issue Tracking List Item
              case "STS_List_GanttTasks":                  // Project Tasks List
              case "STS_ListItem_GanttTasks":           // Project Tasks List Item
              case "STS_List_Survey":                        // Survey List
              case "STS_ListItem_Survey":                 // Survey List Item
              case "STS_List_PictureLibrary":             // Picture Library
              case "STS_ListItem_PictureLibrary":         // Picture Library Item
              case "STS_List_WebPageLibrary":             // Web Page Library
              case "STS_ListItem_WebPageLibrary":         // Web Page Library Item
              case "STS_List_XMLForm":                    // Form Library
              case "STS_ListItem_XMLForm":                // Form Library Item
              case "urn:content-class:SPSSearchQuery":    // Search Query
              case "urn:content-class:SPSListing:News":   // News Listing
              case "urn:content-class:SPSPeople":         // People
              case "urn:content-classes:SPSCategory":     // Category
              case "urn:content-classes:SPSListing":      // Listing
              case "urn:content-classes:SPSPersonListing":// Person Listing
              case "urn:content-classes:SPSTextListing":  // Text Listing
              case "urn:content-classes:SPSSiteListing":  // Site Listing
              case "urn:content-classes:SPSSiteRegistry": // Site Registry Listing

      Grouping list data in XSLT

      I used a linked XSL file to override the output of my list web part, grouped by one of my custom columns called 'Classification'.

      To add in an XSL override link to your XSL file via the list web part properties:


      XSL (uploaded to a SharePoint Document library):

      <xsl:stylesheet xmlns:x="http://www.w3.org/2001/XMLSchema" xmlns:d="http://schemas.microsoft.com/sharepoint/dsp" version="1.0" exclude-result-prefixes="xsl msxsl ddwrt" xmlns:ddwrt="http://schemas.microsoft.com/WebParts/v2/DataView/runtime" xmlns:asp="http://schemas.microsoft.com/ASPNET/20" xmlns:__designer="http://schemas.microsoft.com/WebParts/v2/DataView/designer" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt" xmlns:SharePoint="Microsoft.SharePoint.WebControls" xmlns:ddwrt2="urn:frontpage:internal" xmlns:o="urn:schemas-microsoft-com:office:office">
      <xsl:include href="/_layouts/xsl/main.xsl"/>
      <xsl:include href="/_layouts/xsl/internal.xsl"/>
      <xsl:output method="html" indent="yes" version="4.0"/>
      <xsl:template match="/">
      <xsl:call-template name="MyTemplate" />
      </xsl:template>
      <xsl:key name="classificationKey" match="Row" use="@Classification" />
      <xsl:key name="associatedTitle" match="Row" use="@Title" />
      <xsl:template name="MyTemplate">
      <xsl:for-each select="/dsQueryResponse/Rows/Row[generate-id(.)=generate-id(key('classificationKey', @Classification))]">
      <h3><xsl:value-of select="@Classification" /></h3>
      <xsl:variable name="thisClassification" select="@Classification" />
      <xsl:for-each select="../Row[generate-id()=generate-id(key('associatedTitle', @Title)[@Classification = $thisClassification][1])]">
      <div>
      <strong>Title: </strong>
      <xsl:value-of select="@Title" /><br/>
      <strong>Description: </strong>
      <xsl:value-of select="@Description" disable-output-escaping="yes" /><br/>
      <strong>Link: </strong>
      <a href="{@Link}" title="{@Title}"><xsl:value-of select="@Link"/></a>
      </div>
      </xsl:for-each>
      </xsl:for-each>
      </xsl:template>
      </xsl:stylesheet>


      This is the output:

      Classification 1

      Title 1
      Description 1
      Title 2
      Description 2
      Title 3
      Description 3

      Classification 2

      Title 4
      Description 4
      Title 5
      Description 5

      Monday, February 28, 2011

      Extended Content Query Web Part - 2 Column Box Layout

      Before extending Content Query Web Parts (CQWP) in SharePoint refer to the following related blogs:
      The following example creates a 'Highlight Box' two column layout output from a SharePoint list by applying custom XSLT styles using the Content Query Web Part.  The result looks like this:

      1. Make a copy of the SharePoint XSL stylesheets 'ItemStyle.xsl' and 'ContentQueryMain.xsl' located in the portal root Style Library (http://hostheader/Style%20Library/) and place the copies in a folder called 'Custom' within the Style Library (http://hostheader/Style%20Library/XSL%20Style%20Sheets/Custom/). Rename as 'ItemStyleExtended.xsl' and 'ContentQueryMainExtended.xsl'.

      2. Open ContentQueryMainExtended.xsl in notepad:
        1. Add the following new variables:

          <xsl:variable name="BeginListItemHighlightBoxLeft" select="string('<li class="dfwp-item highlightbox-item left">')" />

          <xsl:variable name="BeginListItemHighlightBoxRight" select="string('<li class="dfwp-item highlightbox-item right">')" />

        2. Inside the OuterTemplate.CallItemTemplate insert a new xsl choose:

          <xsl:choose>
            <xsl:when test="@Style='HighlightBoxTable'">

              <xsl:choose>

                <xsl:when test="$CurPosition mod 2 = 1">

                  <xsl:value-of disable-output-escaping="yes" select="$BeginListItemHighlightBoxLeft" />

                </xsl:when>

                   <xsl:otherwise>

                <xsl:value-of disable-output-escaping="yes" select="$BeginListItemHighlightBoxRight" />

              </xsl:otherwise>

              </xsl:choose>

            </xsl:when>

            <xsl:otherwise>

              <xsl:value-of disable-output-escaping="yes" select="$BeginListItem" />

            </xsl:otherwise>

          </xsl:choose>


      3. Open the ItemStyleExtended.xsl in notepad and create a new template at the end of the existing xsl:

        <xsl:template name="HighlightBoxTable" match="Row[@Style='HighlightBoxTable']" 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>
         
          <xsl:variable name="ImageClass" select="@Class" />


          <div class="highlight">

            <div class="highlightHead">

              <h3><a href="{$SafeLinkUrl}"><xsl:value-of select="@Title"/></a></h3>

            </div>

            <div class="highlightContentCtr">

              <a href="{$SafeLinkUrl}" target="{$LinkTarget}">
        <img align="left" class="{@Class}" src="{$SafeImageUrl}" alt="{@ImageUrlAltText}" /></a>
              <div class="highlightContent">
                <xsl:value-of select="substring(@Description,1,300)" disable-output-escaping="yes"/></div>

            </div>

          </div>


        </xsl:template
        >

      4. Update Custom.css with the following styles:

        <style type="text/css">
        li.highlightbox-item {

           width:49%;
        }
        li.highlightbox-item.left {
           float:left;
           margin-right:10px;
        }
        li.highlightbox-item.right {
           float:right;
           margin-right:0;
        }
        div.highlight {
           background-color: #f7f7f7;
           padding: 0;
           border: 0;
           margin-bottom:10px;
           border-radius-top-left:5px;
           border-radius-top-right:5px;
           -moz-border-radius-topleft:5px;
           -moz-border-radius-topright:5px;
           -webkit-border-top-left-radius:5px;
           -webkit-border-top-right-radius:5px;
        }
        div.highlight div.highlightHead {
           padding: 0.5em;
           font-weight:bold;
           background-color: #e4e4e4;
           border-radius-top-left:5px;
           border-radius-top-right:5px;
           -moz-border-radius-topleft:5px;
           -moz-border-radius-topright:5px;
           -webkit-border-top-left-radius:5px;
           -webkit-border-top-right-radius:5px;
        }
        div.highlight div.highlightHead h3 {
           margin:0;
        }
        div.highlight div.highlightContentCtr {
           min-height:50px;
           border: 1px solid #e4e4e4;
           border-top:0;
        }
        div.highlight div.highlightContentCtr img {
           margin: 0 10px 0 0;
           border: 0;
           padding: 0;
        }
        div.highlight div.highlightContentCtr img.icon {
           width:50px;
           height:50px;
        }
        div.highlight div.highlightContentCtr img.image {
           width:75px;
           height:50px;
        }
        div.highlight div.highlightContent {
           padding: 10px 10px 4px 10px;
        }
        </style>


      5. Add a Content Query Web Part (CQWP) to a page. Do not configure it in any way.

      6. Export the Content Query Web Part to your desktop.



      7. Open the exported CQWP in notepad and edit the following properties:

        <property name="Title" type="string">Extended Content Query</property>

        <property name="ItemXslLink" type="string">/Style%20Library/XSL%20Style%20Sheets/Custom/ItemStyleExtended.xsl</property>


        <property name="MainXslLink" type="string">/Style%20Library/XSL%20Style%20Sheets/Custom/ContentQueryMainExtended.xsl</property>

      8. On the web part page where you would like the CQWP displayed, select Edit, Add a Web Part, Upload a Web Part:


      9. On the web part page where you would like the CQWP displayed, select Edit, Add a Web Part, Imported Web Parts, Extended Content Query


      10. Edit the Extended CQWP properties:
        1. In the properties panel expand the Query node. Select the radio button Show items from the following list and enter the path to the associated SharePoint list, (which requires six columns including: Title, Image, Description, URL, Class and Order). Apply these changes by selecting the Apply button at the bottom of the properties panel.

        2. Expand the Presentation node and in the Grouping and Sorting section set the Sort items by to ‘Order’.



        3. In the Styles section set the Item style to HighlightBoxTable.
        4. In the Fields to display section set as in the screenshot.



        5. Expand the Appearance node and set the Chrome to none.
        6. Select Ok.

        Monday, February 14, 2011

        XSL disable-output-escaping

        Render HTML using 'disable-output-escaping':

        <xsl:value-of select="expression" disable-output-escaping="yes|no" />

        http://www.w3schools.com/xsl/el_value-of.asp

        Attribute Value Description
        select expression Required. An XPath expression that specifies which node/attribute to extract the value from. It works like navigating a file system where a forward slash (/) selects subdirectories.
        disable-output-escaping yes
        no
        Optional. "yes" indicates that special characters (like "<") should be output as is. "no" indicates that special characters (like "<") should be output as "<". Default is "no"