Check if File Exists in XSL (with MSXML3)

Posted on 2005-04-06
Last Modified: 2008-01-16
I using code from sparkplug ( and it works so long as I hardcode the parameter, but a dynamic parameter fails.

----------- snipit of code from sparkplug
<msxsl:script language="javascript" implements-prefix="user"><![CDATA[

          function fileExists(sFilePath)
                 var oFSO= new ActiveXObject("Scripting.FileSystemObject")
                  return oFSO.FileExists(sFilePath);


     <xsl:template match="/">
               <xsl:when test="user:fileExists('c:\test.xml')" >File exists</xsl:when>
               <xsl:otherwise>File does not exist</xsl:otherwise>
----------- end snippet

<xsl:when test="user:fileExists('G:\WWW\Marketplace\InetPub\images\ProductFullSize\vib-3004.jpg')" >File exists</xsl:when>

Works as expected.


<xsl:variable name="ProductImageBig">G:\WWW\Marketplace\InetPub\images\ProductFullSize\<xsl:value-of select="ItemList/Item/@ItemNumber"/>.jpg</xsl:variable>
<xsl:when test="user:fileExists('$ProductImageBig')" >

always returns File does not exist.
Question by:leos_
    LVL 23

    Expert Comment

    do it this way:
    <xsl:when test="user:fileExists($ProductImageBig)" >


    you pass in the variable directly instead of enclosing it in smart quotes.

    LVL 3

    Author Comment

    I tried that.  What happens is the script dies (at the when statement as far as I can tell), ending with:


    In the browser it appears to be chinese.

    What could cause this?
    LVL 23

    Accepted Solution

    ahhh =)
    <xsl:when test="user:fileExists(string($ProductImageBig))" >


    LVL 3

    Author Comment

    nice work b1xml2.  This should help me solve many other problems I've had.
    LVL 23

    Expert Comment

    most welcome =)

    Featured Post

    Enabling OSINT in Activity Based Intelligence

    Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

    Join & Write a Comment

    Browsing the questions asked to the Experts of this forum, you will be amazed to see how many times people are headaching about monster regular expressions (regex) to select that specific part of some HTML or XML file they want to extract. The examp…
    The Confluence of Individual Knowledge and the Collective Intelligence At this writing (summer 2013) the term API ( has made its way into the popular lexicon of the English language.  A few years ago, …
    Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
    Here's a very brief overview of the methods PRTG Network Monitor ( offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

    728 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    20 Experts available now in Live!

    Get 1:1 Help Now