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

Re: Calling a Java extension from XSLT using Saxon B

Subject: Re: Calling a Java extension from XSLT using Saxon B
From: "G. Ken Holman" <gkholman@xxxxxxxxxxxxxxxxxxxx>
Date: Tue, 23 Jun 2009 15:29:20 -0400
Re:  Calling a Java extension from XSLT using Saxon B
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 "&#xd;&#xa;"> ]>
<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>


-- Crane Softwrights Ltd. http://www.CraneSoftwrights.com/s/ Training tools: Comprehensive interactive XSLT/XPath 1.0/2.0 video Video lesson: http://www.youtube.com/watch?v=PrNjJCh7Ppg&fmt=18 Video overview: http://www.youtube.com/watch?v=VTiodiij6gE&fmt=18 G. Ken Holman mailto:gkholman@xxxxxxxxxxxxxxxxxxxx Male Cancer Awareness Nov'07 http://www.CraneSoftwrights.com/s/bc Legal business disclaimers: http://www.CraneSoftwrights.com/legal

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.