Software is like sex... It's better when it's free.

Blog - Test the existence of a file in XSL

Test the existence of a file in XSL

When you want to display images dynamically, if you want to make sure they actually exist, you can do fairly easily directly in XSL:

<xsl:stylesheet xmlns:xsl="" xmlns:php="" version="1.0">
<xsl:output method="xml" encoding="UTF-8" indent="yes" />
  <xsl:template match="root">
        <!-- We suppose node 'id' contains part of the filename -->
        <xsl:variable name="imgSrc" select="boolean(document(string(concat('', id, '.jpg'))))" />
          <xsl:when test="$imgSrc">
            <img src="{concat('', id, '.jpg')}" alt="{id}" />
            <img src="" alt="Not found" />
Tags:  xmlxsl.
Posted the Tuesday 08 september 2009 18:03:04