none
XsltListViewWebPart - Custom Rendering for a DateTime Field in an external XSLT vs Embedded Designer XSLT (must replace the "mode" with a new value)

    Question

  • 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(&apos;/_layouts/images/KPIPeppers-2.GIF&apos;); 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(&apos;/_layouts/images/KPIPeppers-1.GIF&apos;); 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(&apos;/_layouts/images/KPIPeppers-0.GIF&apos;); 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



    Friday, January 04, 2013 10:03 PM

Answers

All replies