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

Calling a Java extension from XSLT using Saxon B

Subject: Calling a Java extension from XSLT using Saxon B
From: "Blaine McNutt (rbmcnutt)" <rbmcnutt@xxxxxxxxx>
Date: Tue, 23 Jun 2009 12:19:40 -0700
 Calling a Java extension from XSLT using Saxon B
I am not a Java programmer, 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). This topic has
been discussed a lot on various aliases, and despite my best efforts, I'm
unable to unravel the mystery. 

I've included what I believe to be relevant information.

Error Message:
--------------
Error at xsl:value-of on line 15 column 48 of nxs-test-image-exists.xsl:
  XPST0017: XPath syntax error at char 20 on line 15 in
{nxs:fileExist(@osrc)}:
    Cannot find a matching 1-argument function named
{java:FileExist}fileExist()
Failed to compile stylesheet. 1 error detected.

Saxon-B 9.1.7 J stored in xmlsrc/xTools/saxon9.
-----------------------------------------------

Java program (compiled and the FileExist.class file stored in
xmlsrc/xTools/saxon9/classes)

/* Source: http://p2p.wrox.com/xslt/71563-xslt-check-if-directory-exist.html
*/

import java.io.File;

public class FileExist {

    private static boolean exist;

    public static boolean fileExist(String myfile) {

        exist = new File(myfile).exists();

        return exist;

    }
}

XML Snippet for img element
---------------------------

...
<img osrc="../../images/1982.jpg" />

...

XSLT
------

<?xml version="1.0" encoding="UTF-8"?>

<xsl:stylesheet version="2.0"
                xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                xmlns:nxs="java:FileExist">

<xsl:output method="xml"/>

<xsl:template match="/">
                <xsl:apply-templates />                                    
</xsl:template>

<xsl:template match="img">
                <xsl:value-of select="nxs:fileExist(@osrc)" />
</xsl:template>
    
</xsl:stylesheet>

Korn Shell script/command line call:
------------------------------------

# define saxon command line
saxon="java -classpath xTools/saxon9/classes; -jar -Xmx1G
xTools/saxon9/saxon9.jar -tree:tiny -dtd:off -ext:on "
# call transform
$saxon deliverables/help/helpFile.xml  xslt/nxs-test-image-exists.xsl >
imageerror.xml


Thank you for any insights you might offer.

Blaine

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-2011 All Rights Reserved.