Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old October 17th, 2005, 05:57 PM
Registered User
 
Join Date: Oct 2005
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default howto test document exists

Is there a function can be used in xsl:if to test document exists?

The following xsl failed in IE

<xsl:if test="document('xyz.xml')">
document exists
</xsl:if>
 
Old October 19th, 2005, 01:11 PM
Authorized User
 
Join Date: Jun 2003
Posts: 60
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to rushman
Default

Hello!

Well I tried this and it works... Are you sure the document is really there?

<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
 <xsl:template match="/">
  <html>
   <head/>
   <body>
    <h1>
    <xsl:choose>
     <xsl:when test="boolean(document('xyz.xml'))">
      <xsl:text>doc exists</xsl:text>
     </xsl:when>
     <xsl:otherwise>
      <xsl:text>doc doesn't exists</xsl:text>
     </xsl:otherwise>
    </xsl:choose>
    </h1>
   </body>
  </html>
 </xsl:template>
</xsl:stylesheet>

Rushman

Dijkstra's law on Programming and Inertia:

If you don't know what your program is supposed to do, don't try to write it.
 
Old October 19th, 2005, 05:56 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

Unfortunately you can't rely on this working: failure to access a document is a "recoverable error" so different processors will do different things (and it may depend on the kind of error, e.g. on-existent document versus bad XML content).

2.0 has a doc-available() function but the only ways to do it in 1.0 are processor-specific

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference





Similar Threads
Thread Thread Starter Forum Replies Last Post
What’s the .NET Way to test if Folder Exists? BrianWren Pro Visual Basic 2005 3 March 14th, 2007 08:35 AM
What’s the .NET Way to test if Folder Exists? BrianWren Visual Basic 2005 Basics 3 January 12th, 2007 07:32 PM
What’s the .NET Way to test if Folder Exists? BrianWren VB.NET 0 November 30th, 2006 02:46 PM
How to test if a column exists in a table jtrifts SQL Server 2000 2 February 16th, 2006 02:25 PM
Test to see if a SQL Server exists Mitch Access 2 July 18th, 2003 04:29 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.