I never really cared about learning or using XSL and XSL style sheets in my projects. But then I was wrong, I should have mastered this, it is an important weapon in a SharePoint consultant's arsenal.
In this blog post I try to note down my experience with XSL so that I can refer back to this again later.
1. If you see characters like ampersand (&) appearing as & in your List view with custom XSL template then you got to disable output escaping.
disable-output-escaping="yes"
2. For one of my projects I had to dynamically bind a URL field in a DataView webpart. The requirement was to display different views (InfoPath) of a list based on two column values in the list. One of these values was set by a work flow.
There are different ways to do this and there may be better ways of achieving this but this is how I did it:
<xsl:choose>
<xsl:when test="@Status1 = 4 and @Status2 = 4">
<a onclick="javascript: NewItem2(event, "/sites/Intranet/Lists/Change/Item/editifs.aspx?ID={@ID}&DefaultView=View2&IsDlg=1"); return false;" href="/sites/Intake/Change/" title="{@Title}">
<xsl:value-of select="substring(@Title,1,30)" disable-output-escaping="yes" /></a>
</xsl:when>
<xsl:when test="@Status1 = 5 and @Status2 = 5">
<a onclick="javascript: NewItem2(event, "/sites/Intranet/Lists/Change/Item/editifs.aspx?ID={@ID}&DefaultView=View1&IsDlg=1"); return false;" href="/sites/intranet/" title="{@Title}">
<xsl:value-of select="substring(@Title,1,30)" disable-output-escaping="yes" /></a>
</xsl:when>
</xsl:choose>
In the above code I'm choosing between View1 or View2 based on the value of the fields Status1 and Status2.
It would have been better to just set a variable and not the entire Anchor in the xsl:when, much more to learn!
3. Format Date in DataView Webpart
The following XSL can be used to format date in DataView web part:
ddwrt:FormatDateTime(string(@SomeDate),4105,'dd-MMM-yyyy')
To get format date and time in 12 hour format:
ddwrt:FormatDateTime(string(@SomeDate),4105,'dd-MMM-yyyy hh:mm tt')
4105 is the LCID more of which can be found here: http://support.microsoft.com/default.aspx?id=221435
4. There is no Modified By available within XSL, you have to use @Editor.title to get the display name.
5. In a DataView Webpart you could do grouping and this is how it appears on browser:
If you want to get rid of that Group By column name you need to remove the following XSL from the webpart:
To be continued..
In this blog post I try to note down my experience with XSL so that I can refer back to this again later.
1. If you see characters like ampersand (&) appearing as & in your List view with custom XSL template then you got to disable output escaping.
disable-output-escaping="yes"
2. For one of my projects I had to dynamically bind a URL field in a DataView webpart. The requirement was to display different views (InfoPath) of a list based on two column values in the list. One of these values was set by a work flow.
There are different ways to do this and there may be better ways of achieving this but this is how I did it:
<xsl:choose>
<xsl:when test="@Status1 = 4 and @Status2 = 4">
<a onclick="javascript: NewItem2(event, "/sites/Intranet/Lists/Change/Item/editifs.aspx?ID={@ID}&DefaultView=View2&IsDlg=1"); return false;" href="/sites/Intake/Change/" title="{@Title}">
<xsl:value-of select="substring(@Title,1,30)" disable-output-escaping="yes" /></a>
</xsl:when>
<xsl:when test="@Status1 = 5 and @Status2 = 5">
<a onclick="javascript: NewItem2(event, "/sites/Intranet/Lists/Change/Item/editifs.aspx?ID={@ID}&DefaultView=View1&IsDlg=1"); return false;" href="/sites/intranet/" title="{@Title}">
<xsl:value-of select="substring(@Title,1,30)" disable-output-escaping="yes" /></a>
</xsl:when>
</xsl:choose>
In the above code I'm choosing between View1 or View2 based on the value of the fields Status1 and Status2.
It would have been better to just set a variable and not the entire Anchor in the xsl:when, much more to learn!
3. Format Date in DataView Webpart
The following XSL can be used to format date in DataView web part:
ddwrt:FormatDateTime(string(@SomeDate),4105,'dd-MMM-yyyy')
To get format date and time in 12 hour format:
ddwrt:FormatDateTime(string(@SomeDate),4105,'dd-MMM-yyyy hh:mm tt')
4105 is the LCID more of which can be found here: http://support.microsoft.com/default.aspx?id=221435
4. There is no Modified By available within XSL, you have to use @Editor.title to get the display name.
5. In a DataView Webpart you could do grouping and this is how it appears on browser:
<b>And this is how it appears after:
<xsl:value-of select="$fieldtitle" />
</b>
<xsl:if test="$fieldtitle">: </xsl:if>
To be continued..
Comments
I'm not sure if you can call this function without LCID as a parameter. And OOB I don't see how we can get the current locale of the user for the dataview webpart.
If you can make a connection to select the date in DataView webpart you could use a Date Filter webpart and connect it to your DataView webpart