Tag Archives: XSLT

Make clicking on document icons open the actual document

Requirement

Make clicking on document icons open a document instead of selecting a row in the SharePoint list view (Just like in 2007).

Solution

  • Download the file: fldtypes_docicon.xsl
  • Copy it to C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\template\layouts\XSL on ALL your SharePoint Web Front End servers.
  • Do an IISRESET /Noforce on each server

Reference

See the following TechNet article for more information.

http://support.microsoft.com/kb/2457975

Comments ( 0 )

Open Workflow Initiation form after InfoPath form submit

Requirement

After users complete an InfoPath web browser form, we want the user to be redirected to the approval workflow initiation form after the InfoPath form closes. We could not use the option to start the workflow on item creation as we needed to user to select an approver or multiple approvers.

Solution

We managed to get this working by creating a page with an InfoPath form webpart and a data view web part. The InfoPath form sends a configured set of parameters to the dataview webpart upon submission. The dataview webpart is then configured with a HTTP redirect so that it opens the workflow initiation form as soon as it receives data from the InfoPath form.

Configure your InfoPath form submit rule

  1. Select your submit button -> Manage Rules
  2. Ensure that ‘Send data to web part’ is set after ‘Submit using a data connection’.

 

Configure the Form Parameters

  1. Open your InfoPath form -> File -> Form Options
  2. Under Property Promotion, add at least one property to identify each item in the list. You may add additional items if you wish to do filtering.
  3. Click on OK and Publish your form when done.

Creating a new page and add the InfoPath form and Dataview Webparts.

  1. Open SharePoint Designer 2010 -> Site Pages -> New Page.
  2. Add an InfoPath form webpart and link it to your form.
  3. Add a dataview webpart and link it to your form library.

Configure the Dataview webpart

This webpart is simply used to get data from the InfoPath form, build the URL to the workflow initiation form, and redirect the user to it. After configuring the webpart, you should set its status to hidden.

  1. Select your dataview webpart -> Options (on the ribbon) -> Add/Remove Columns
  2. I selected only the ‘Name’ column as this webpart is going to be hidden anyway.
  3. Under Parameters (on the ribbon), add your filter attribute and unique identifier. In my case, I used ‘RequestNo’ to uniquely identify each record, and ‘RecruitChoice’ as a filter.
  4. With your parameters set up, click on Manage Connections (on the ribbon).
  5. Add a new connection with action ‘Get Parameters from’.
  6. Select ‘Connect to a Web Part on this page’ -> Target Web Part: InfoPath Form Web Part
  7. Target action: Send Data To
  8. Map the parameters in the InfoPath form to the parameters you set up in the dataview webpart.
  9. Click finish

Dataview Parameters

 

Webpart Connection

The next thing you need to do is set up a filter on the Dataview Webpart.

  1. Select the Dataview Webpart -> Filter (on the ribbon)
  2. Map the promoted property from your InfoPath form (in my case it is RequestNo) to the parameter you created for the DVWP ([RequestNo])
  3. Click OK.

Modify the Dataview Webpart’s XSL template

On the same page, switch your view to Code view (if you haven’t already done so).

Look for the line that says:

<xsl:template name=”dvt_1.rowview”>

..

..

</xsl:template>

Replace its entire contents with the following code, changing the parts in blue to suit your environment and requirements.

Note: In my case, I wanted to start seperate workflows depending on whether RecruitChoice = ‘staff’ or ‘workforce’.

<xsl:template name=”dvt_1.rowview”>
<tr>
<td>
<xsl:if test=”contains($RecruitChoice, ‘staff’)”>
<meta http-equiv=”refresh” content=”0;url=http://sharepoint/_layouts/IniWrkflIP.aspx?List=c4ea0309-8025-4997-a438-1b9b2443ba8b&amp;ID={@ID}&amp;TemplateID=7d892fbe-052d-4c53-9f73-b7347c5364e5“/>
</xsl:if>
<xsl:if test=”contains($RecruitChoice, ‘workforce’)”>
<meta http-equiv=”refresh” content=”0;url=http://sharepoint/_layouts/IniWrkflIP.aspx?List=c4ea0309-8025-4997-a438-1b9b2443ba8b&amp;ID={@ID}&amp;TemplateID=253f428b-e505-4dc3-87f1-954d3a5adbfc“/>
</xsl:if>
</td>
</tr>
</xsl:template>

Save the page and test the form.

If you have configured everything correctly, save the page and open it in the browser.

Complete the form and test with the parameters you specified earlier.

Your form should automatically direct to the workflow initiation form after you click the ‘Submit’ button.

Things to note

  1. Since the URL of the workflow initiation form is hardcoded, if you globally re-republish your workflow, you will need to update the TemplateID of the workflow.

 

 

Comments ( 0 )

Content Query Webpart and Data View Webpart – Modal Dialogs

Requirement

We have a content query webpart that displays information from a list on a subsite. When a user clicks on a link on the webpart, we want the link to open in a Modal dialog.

Solution

  1. Open SharePoint Designer 2010
  2. Go to All Files -> Style Library -> XSL Style Sheets -> ItemStyle.xsl -> Modify
  3. Copy one of the existing templates, e.g. Default, change the name and modify the XSL according to your needs.

Here is a simple example, that I created for ‘Job Vacancies’.

Note the bits in blue where javascript is used to force the links to open in a dialog window.

<xsl:template name=”JobVacancy” match=”Row[@Style=’JobVacancy’]” mode=”itemstyle”>

<xsl:variable name=”Created”>

<xsl:value-of select=”ddwrt:FormatDateTime(string(@Created) ,1033 ,’dd/MM/yyyy’)” />

</xsl:variable>

<xsl:variable name=”_DCDateCreated”>

<xsl:value-of select=”ddwrt:FormatDateTime(string(@_DCDateCreated) ,1033 ,’dd/MM/yyyy’)” />

</xsl:variable>

<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}” title=”{$DisplayTitle}”>

<xsl:value-of select=”$_DCDateCreated”/> – <xsl:value-of select=”$DisplayTitle”/>

</a>

</div>

</xsl:if>

<div class=”link-item”>

<xsl:call-template name=”OuterTemplate.CallPresenceStatusIconTemplate”/>

<script type=”text/javascript”>

function ModalDialog(url) {

var options = {

url: url,

title: “Job Vacancies”,

allowMaximize: true,

showClose: true,

width: 800,

height: 600,

dialogReturnValueCallback: silentCallback};

SP.UI.ModalDialog.showModalDialog(options);

}

function silentCallback(dialogResult, returnValue) {

}

function refreshCallback(dialogResult, returnValue) {

SP.UI.Notify.addNotification(‘Operation Successful!’);

SP.UI.ModalDialog.RefreshPage(SP.UI.DialogResult.OK);

}

</script>

<a href=”javascript:ModalDialog(‘{$SafeLinkUrl}’)” target=”{$LinkTarget}” title=”{$DisplayTitle}”>

<xsl:value-of select=”$_DCDateCreated”/> – <xsl:value-of select=”$DisplayTitle”/>

</a>

<div class=”description”>

<xsl:value-of select=”@Description” />

</div>

</div>

</div>

</xsl:template>

 

You can also use the same bit of code to force links in your data view web part to open in a dialog window.

  • Edit Webpart properties of your Data View Web Part
  • Under Data View Properties -> Click on XSL Editor
  • Copy the entire contents to a code editor like Visual Studio or Notepad++.
  • Search for the string ‘a href’ – there should only be 1 string.
  • Just above the line ‘<a href….”>
  • Add in the following code:

<script type=”text/javascript”>

function ModalDialog(url) {

var options = {

url: url, title: “<change this to your title>”,

allowMaximize: true,

showClose: true,

width: 800,

height: 600,

dialogReturnValueCallback: silentCallback};

SP.UI.ModalDialog.showModalDialog(options);

}

function silentCallback(dialogResult, returnValue) {

}

function refreshCallback(dialogResult, returnValue) {

SP.UI.Notify.addNotification(‘Operation Successful!’);

SP.UI.ModalDialog.RefreshPage(SP.UI.DialogResult.OK);

}

</script>

  • Next, modify the URL so that it looks like this:

 <a href=”javascript:ModalDialog2(‘http://sharepoint/DispForm.aspx?ID={@ows_ID}‘)“>

  • Copy the XSL back to the webpart and save.

Your links should now open in a dialog window.

 

Comments ( 0 )

Creating a Tag Cloud in SharePoint

What you need

*Download, install and activate the Metadata Webpart from Codeplex

Note* I had to download the solution and make some slight modifications before I managed to get it to work. See here.

Solution

Activate the feature for the webpart at the site collection level.

Add the webpart to the page containing your list.

Modify the webpart properties to point to the correct list and field.

Modify the XSL String to the following:

<?xml version=’1.0′ encoding=’utf-8′?>

<xsl:stylesheet version=’1.0′ xmlns:xsl=’http://www.w3.org/1999/XSL/Transform’ xmlns:msxsl=’urn:schemas-microsoft-com:xslt’ exclude-result-prefixes=’msxsl’>

<xsl:output method=’html’ indent=’yes’/> <xsl:template name=’terms’ match=’//termset’>

<xsl:param name=’d’/> <div class=’termset’ style=’padding: 10px 0px; text-align: center;’>

<xsl:variable name=’AvgHit’><xsl:value-of select=’sum(//term/itemcount) div count(//term[itemcount > 0])’/>

</xsl:variable>

<xsl:for-each select=’//term[itemcount > 0]’>

<xsl:sort select=’name’/>

<xsl:element name=’span’>

<xsl:attribute name=’style’> padding-right: 5px; vertical-align: middle; padding-left: 5px;

<xsl:if test=’itemcount > $AvgHit’>font-size:1.5em;</xsl:if>

</xsl:attribute>

<xsl:element name=’a’>

<xsl:attribute name=’href’>?FilterField1=Wiki_x0020_Page_x0020_Categories&amp;FilterValue1=<xsl:value-of select=’name’/></xsl:attribute>

<xsl:value-of select=’name’/>

</xsl:element>

</xsl:element>

<xsl:if test=’position() != last()’>

<span style=”font-size: 90%; color:#ccc; vertical-align:middle;”> | </span> </xsl:if>

</xsl:for-each>

</div>

</xsl:template>

</xsl:stylesheet>

Modify the field name to match the one you want (in red bold).

Save all webpart settings.

Your tag cloud should look something like this:

When you click on each on the tags, your page will refresh with the list items that correspond to that tag. Note, this will only work if the list view webpart and tag cloud are on the same page.

Comments ( 0 )

Document Icon Link in SharePoint List not working

Problem

Clicking on a document icon does not link you to the document.

Solution

Microsoft has published a fix for this issue. Create a file called fldtypes_docicon.xsl and copy the XSLT code supplied by Microsoft into the file. Move the file to the following location:

C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\TEMPLATE\LAYOUTS\XSL

Code and instructions available at:

http://support.microsoft.com/default.aspx?scid=kb;en-US;2457975

Comments ( 0 )