Since I am not familar with how your images are being stored, or how you plan on determining what's an image, verse just plain text - I'm flying kinda blind, but this is what I can offer up:
Might be better off passing the return value from your INPUT element to a script that does an If...Exists on the file ( to see if it's a valid image ) and either inserts a <IMG> back into the document or straight text.
Then you just need a <DIV> tag in your HTML that has an ID, you reference in your script and do a call to the DOM method innerHTML, to insert your value.
Through XSL ... you might be able to work something out with <xsl:choose> statements, but again, since I do not know how your images are stored, I'm not certain how you'll validate the text is a valid image or just "text".
If you can expand more on your situation, it might help.