Thursday, March 8, 2007

Displaying a Document Icon in a Data View

To display the correct document icon in a dataview, use the following XSLT source:

<a target="_self">
   
<xsl:attribute name="href">
      
<xsl:value-of select="@FileRef"/>
   </
xsl:attribute> 
   
<img border="0">
      
<xsl:attribute name="src">
         /_layouts/images/
<xsl:value-of select="ddwrt:MapToIcon(string(@HTML_x0020_File_x0020_Type),string(@File_x0020_Type))"/>
      </
xsl:attribute> 
   
</img>
</a>

The MapToIcon method derives the correct icon name from the supplier document type (but note it returns only the icon file name, not the path).

No comments: