[Home] [By Thread] [By Date] [Recent Entries]
At 2009-06-23 12:19 -0700, Blaine McNutt (rbmcnutt) wrote:
I am not a Java programmer, Nor am I ... so I look for off-the-shelf solutions for such problems. but I would like to use an extension to check for the existence of an image file referenced by an XML file (as I believe that is the only way to check for the existence of a non-XML file). Yes. This topic has been discussed a lot on various aliases, and despite my best efforts, I'm unable to unravel the mystery. Your post prompted me to test an old XT stylesheet with Saxon B and it works! It would seem that Mike has the foresight to support other implementations' use of Java extensions. I hope the example below helps as it does not involve writing any Java code. . . . . . . . . . Ken X:\samp>type exists.xml
<?xml version="1.0"?>
<files>
<file>exists.xml</file>
<file>exists.junk</file>
<file>exists.xsl</file>
</files>
X:\samp>type exists.xsl
<?xml version="1.0"?><!--exists.xsl-->
<!--XSLT 1.0 - http://www.CraneSoftwrights.com/training -->
<!DOCTYPE xsl:stylesheet [ <!ENTITY nl "
"> ]>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:file="http://www.jclark.com/xt/java/java.io.File"><xsl:output method="text"/> <xsl:template match="/">
<xsl:if test="not( function-available('file:exists') and
function-available('file:new') )">
<xsl:message terminate="yes">
<xsl:text>Required Java file facilities </xsl:text>
<xsl:text>are not available</xsl:text>
</xsl:message>
</xsl:if>
<xsl:for-each select="//file"> <!--process each file-->
<xsl:text>File </xsl:text><xsl:value-of select="."/>
<xsl:text>: </xsl:text> <!--display file name-->
<xsl:choose> <!--report existence-->
<xsl:when test="file:exists(file:new(string(.)))">
<xsl:text>exists&nl;</xsl:text>
</xsl:when>
<xsl:otherwise>
<xsl:text>does not exist&nl;</xsl:text>
</xsl:otherwise>
</xsl:choose>
</xsl:for-each>
</xsl:template></xsl:stylesheet> X:\samp>java -jar p:\xml\xslt\saxon9\saxon9.jar exists.xml exists.xsl Warning: at xsl:stylesheet on line 6 column 66 of exists.xsl: Running an XSLT 1.0 stylesheet with an XSLT 2.0 processor File exists.xml: exists File exists.junk: does not exist File exists.xsl: exists X:\samp>
|

Cart



