• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 633
  • Last Modified:

Check if File Exists in XSL (with MSXML3)

I using code from sparkplug (http://www.experts-exchange.com/Web/Web_Languages/XML/Q_20586223.html) 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);
          }

     ]]>
     </msxsl:script>

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


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

Works as expected.

However,

<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.
0
leos_
Asked:
leos_
  • 3
  • 2
1 Solution
 
b1xml2Commented:
do it this way:
<xsl:when test="user:fileExists($ProductImageBig)" >

</xsl:when>

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

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

?????????•???????????????????????•??????????????????????????•???????????????????????????????????????????
4??????????????????????????????????????????????????4????????????????????????????•????????????

In the browser it appears to be chinese.

What could cause this?
0
 
b1xml2Commented:
ahhh =)
<xsl:when test="user:fileExists(string($ProductImageBig))" >

</xsl:when>

0
 
leos_Author Commented:
nice work b1xml2.  This should help me solve many other problems I've had.
0
 
b1xml2Commented:
most welcome =)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now