Meta
- Saxon XSLT processor (v. 9.1.8)
- Java
- XSLT 2.0
I got a simple example of a java class file and some xsl transformation. My goal is to run my custom java functions from the class file within the XSLT process (via SAXON). How is this possible? When I start the below described batch file the cmd displays an error calling me the function is not known to saxon. So I have to add my class to the Java / or Saxon CLASSPATH?
The transformation should copy all XML data and (return &) display the dimension of imagefiles.
My XSL Transformation
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:ImageInfo="java:ImageInfo"
version="2.0">
<xsl:output method="xml"/>
<xsl:template match="@* | node()">
<xsl:copy>
<xsl:apply-templates select="@* | node()"/>
</xsl:copy>
<xsl:template/>
<xsl:template match="img">
<xsl:copy>
[image] file found: <xsl:value-of select="ImageInfo:getImageWidth(@src)"/> x <xsl:value-of select="ImageInfo:getImageHeight(@src)"/>
</xsl:copy>
</xsl:template>
Java Class
import javax.swing.ImageIcon;
public class ImageInfo {
String filename;
ImageIcon img;
public ImageInfo(String filename) {
this.filename = filename;
img = new ImageIcon(filename);
}
public int getWidth() {
return img.getIconWidth();
}
public int getHeight() {
return img.getIconHeight();
}
}
Saxon command line call (via .BAT)
java -jar "%~dp0\saxonb9-1-0-8j\saxon9.jar" -s:"data.xml" -xsl:"transformation.xsl" -o:"result.xml"