[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 629
  • 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

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

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