[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

RE: Test if an (image) file exists

Subject: RE: Test if an (image) file exists
From: "Michael Kay" <mike@xxxxxxxxxxxx>
Date: Wed, 8 Jun 2005 21:36:32 +0100
java test file exists
> I'd like to test if image files exist in a target directory on my file
> system before adding links to them in html output (I need to check on
> $filename.jpg or $filename.gif and other variations.) Should 
> I use a Java
> extension function in my XSLT or are there now better ways to 
> do this with
> in-built XSLT functions, using unparsed-text() for example? 

You need to use extension functions. Assuming that the reference to the
image is in an attribute called @src, and that it takes the form of a
relative URI (relative to the document that contains the reference), you
will need something like this:

<xsl:variable name="absoluteURI" select="resolve-uri(@src, base-uri(.))"
as="xs:anyURI"/>
<xsl:if test="file:exists(file:new($absoluteURI))"
xmlns:file="java@xxxxxxxxxxxx">...

> But if I pass this template a filename (xs:string) I get the following
> error:
> 
> "There is more than one method matching the function call 
> file:new, and
> there is insufficient type information to determine which one 
> should be used." 
> 
Java provides File.new(string) and File.new(URI), so Saxon needs to know at
compile time whether the argument is a string or a URI. In this case the
function was called as file:new($param) where $param was declared as

<xsl:param name="param"/>

with no type information. You can probably fix the problem by changing the
declaration to

<xsl:param name="param" as="xs:string"/>

or by writing the function call as file:new($param as xs:string)

(or use xs:anyURI if that's what it is)

Michael Kay
http://www.saxonica.com/

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.