RE: [xsl] check if document exists

Subject: RE: [xsl] check if document exists
From: "Michael Kay" <mike@xxxxxxxxxxxx>
Date: Fri, 19 May 2006 17:58:56 +0100
In 1.0, when document() uses a URI that doesn't exist, the processor can
either return nothing or throw an error. In 2.0, it's obliged to throw an
error; but a new doc-available() function is provided so you can test for
the existence of the document in advance.

However, your URI ends in .png, which suggests that it might not be an XML
file. In that case doc-available() should return false, because document()
would fail to parse the contents of the file. You can use
unparsed-text-available() to test for existence of a text file - but even
that is not designed to test for binary files. Use an extension function
that invokes File.exists() in the Java library.

Michael Kay


> -----Original Message-----
> From: Rick Roen [mailto:Rick@xxxxxxxxxxxxxxxxxx] 
> Sent: 19 May 2006 17:54
> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Subject: [xsl] check if document exists
> I'm trying to check if a document exists before I do 
> something in a XSL 2.0 stylesheet, however it fails using XML Spy:
> 			<xsl:variable
> name="postnetfile">.\postnet<xsl:value-of
> select="../@zip"/>.png</xsl:variable>
> 			<xsl:choose>
> 			<xsl:when 
> test="boolean(document($postnetfile))">
> 			<fo:block padding-left="3mm" 
> padding-top="5mm"> found postnet file
> 				<!--<fo:external-graphic><xsl:attribute
> name="src"></xsl:attribute></fo:external-graphic>-->
> 			</fo:block>
> 			</xsl:when>
> 			</xsl:choose>
> Result: "XSL transformation failed ue to the following error: 
> Error in XPath 2.0 expression Error retrieving resource - 
> 'C:\temp\postnet94030.png'
> Can someone tell my what is wrong?
> Rick

Current Thread