I found something like this on the xWiki web site but it doesn't quite work.
This is what I put on the page.
#set($attachment=$doc.getAttachment("MyFile.doc"))
#mimetypeimg($attachment.getMimeType().toLowerCase() $attachment.getFilename().toLowerCase())
"MyFile.doc" is an attached MS Word document. (Attached to that page.)
The funny thing about it is that when the page displays it shows the ICON followed by some extra stuff that looks like this:
doc?" title="
doc?"/>
The problem seems to lie in the html where the code generated by the Velocity stuff above looks like this:
<img src="/xwiki/skins/albatross/mimetypes/word.png"
alt="<a class="wikicreatelink" href= "/xwiki/bin/edit/WARS/doc?parent=WARS.2005&editor=wysiwyg"><span class="wikicreatelinktext" >doc</span><span class="wikicreatelinkqm">?</ span></a>" title="<a class="wikicreatelink" href="/xwiki/bin/edit/WARS/doc?parent=WARS.2005&editor=wysiwyg"><span class= "wikicreatelinktext">doc</span><span class="wikicreatelinkqm" >?</span></a>"
/>