XsltListViewWebPart - Custom Rendering for a DateTime Field in an external XSLT vs Embedded Designer XSLT (must replace the "mode" with a new value)
-
Friday, January 04, 2013 10:03 PM
I have a list and I've used SPD2010 to edit its style. The changes were the following:
1) Add KPI Pepper to a choice column depending on Red/Green/Yellow
2) Take a DateTime column and just show its year.
The XSLT templates look like this.
<xsl:template name="FieldRef_body.Status" ddwrt:dvt_mode="body" match="FieldRef[@Name='Status']" mode="body" ddwrt:ghost=""> <xsl:param name="thisNode" select="."/> <span> <xsl:attribute name="style"> <xsl:if test="normalize-space($thisNode/@Status) = 'Red'" ddwrt:cf_explicit="1" xmlns:ddwrt="http://schemas.microsoft.com/WebParts/v2/DataView/runtime">font-size: 0px; color: transparent; background-image: url('/_layouts/images/KPIPeppers-2.GIF'); padding: 15px 10px 10px 10px; background- center; background-repeat: no-repeat;</xsl:if> <xsl:if test="normalize-space($thisNode/@Status) = 'Yellow'" ddwrt:cf_explicit="1" xmlns:ddwrt="http://schemas.microsoft.com/WebParts/v2/DataView/runtime">font-size: 0px; color: transparent; background-image: url('/_layouts/images/KPIPeppers-1.GIF'); padding: 15px 10px 10px 10px; background- center; background-repeat: no-repeat;</xsl:if> <xsl:if test="normalize-space($thisNode/@Status) = 'Green'" ddwrt:cf_explicit="1" xmlns:ddwrt="http://schemas.microsoft.com/WebParts/v2/DataView/runtime">font-size: 0px; color: transparent; background-image: url('/_layouts/images/KPIPeppers-0.GIF'); padding: 15px 10px 10px 10px; background- center; background-repeat: no-repeat;</xsl:if> </xsl:attribute> <xsl:value-of select="$thisNode/@*[name()=current()/@Name]" /> </span></xsl:template> <xsl:template name="FieldRef_ValueOf.Year" ddwrt:dvt_mode="body" ddwrt:ghost=""> <xsl:param name="thisNode" select="."/> <xsl:value-of select="ddwrt:FormatDateTime(concat(substring(string($thisNode/@Year),4,3),substring(string($thisNode/@Year),1,3),substring(string($thisNode/@Year),7,4)),1033,'yyyy')"/> </xsl:template>
The issue arrises when I take all contents of the Xsl element out of that list-view and then paste them into an .xsl file and put that in the style library. Then, reference that as an external XSL file.
The Status column still shows the peppers image.... great!
The DateTime column "Year" no longer shows just the Year... it shows the full text date.
Is there a difference the template name attribute when calling it from external? When tracking through fldtypes.xsl it looks that the name should be (for DateTime types) FieldRef_ValueOf and I presume somewhere that the appending of ".Year" or ".InternalFieldNameOfDateTimeField" is the way that you can target one DateTime field over another.
Has anyone successfully formatted a datetime field without embedding their XSL directly in the web part? I'd like to have this be more maintainable and use an external stylesheet.
Thanks
- Edited by With Great SharePoint Comes Great Responsibility Friday, January 04, 2013 10:03 PM
- Edited by With Great SharePoint Comes Great Responsibility Monday, January 07, 2013 3:32 PM
All Replies
-
Saturday, January 05, 2013 6:16 PM
Moving XSL out into an external file shouldn't change its functionality at all. I externalize my XSL in DVWPs all the time, and it should work the same with an XLVWP.
M.
Sympraxis Consulting LLC - Marc D Anderson's Blog - @sympmarc - jQuery Library for SharePoint Web Services (SPServices)
- Edited by Marc D Anderson MVPMVP Saturday, January 05, 2013 6:18 PM
- Edited by Marc D Anderson MVPMVP Saturday, January 05, 2013 6:19 PM
-
Monday, January 07, 2013 3:21 PM
I would think so as well however, its pretty clear, the style stops working. Copying and pasting between the two locations changes the behaviour.
Looks like a bug.
-
Monday, January 07, 2013 3:30 PM
I found the trick.
http://sharepoint.stackexchange.com/questions/54330/show-created-field-with-only-date-in-xsl
I'd included the match attribute before however, the key in this situation is that you must include the "mode" attribute to get your custom rendering template to work.
<xsl:template name="FieldRef_ValueOf.Year" match="FieldRef[@Name='Year']" mode="DateTime_body" ddwrt:ghost=""> <xsl:param name="thisNode" select="."/> <xsl:value-of select="ddwrt:FormatDateTime(concat(substring(string($thisNode/@Year),4,3),substring(string($thisNode/@Year),1,3),substring(string($thisNode/@Year),7,4)),1033,'yyyy')"/> </xsl:template>
The mode attribute is not populated correctly by designer and must be "DateTime_body" in this case to properly take effect.- Edited by With Great SharePoint Comes Great Responsibility Monday, January 07, 2013 3:31 PM
- Marked As Answer by With Great SharePoint Comes Great Responsibility Monday, January 07, 2013 3:31 PM

