You are correct I am using Instant Saxon. In the book it says that the
example should ork unchanged for Saxon or Xalan despite the
"xml.apache.org/xslt" namespace and that it works because you use the
processors' shortcut conventions for encoding Java class in the namespace.
I am not commited to any processor so I assume this should work with Xalan.
Linc
----- Original Message -----
From: "Michael Kay" <mhk@xxxxxxxxx>
To: <xsl-list@xxxxxxxxxxxxxxxxxxxxxx>
Sent: Saturday, January 03, 2004 8:39 PM
Subject: RE: XSLT/Java does not identify an external Java class
> Calling extension functions depends on which processor you are using, so
> you need to give us this information! It looks to me as if you are
> trying to run an example that was written for Xalan but using the Saxon
> processor. In fact, it looks as if you are using Instant Saxon, which
> means you are using the Microsoft JVM, which has quite different ways of
> managing the classpath from the Sun JVM.
>
> The message means that the JVM didn't find the class on the classpath.
>
> Michael Kay
>
> > -----Original Message-----
> > From: owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> > [mailto:owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx] On Behalf Of Linc
> > Sent: 03 January 2004 00:31
> > To: XSL-List@xxxxxxxxxxxxxxxxxxxxxx
> > Subject: XSLT/Java does not identify an external Java class
> >
> >
> > Hi,
> >
> > I am having difficulty getting an example working from the
> > book 'XSLT cookbook' by Sal Mangano, recipe 12.3 (page 542).
> > I receive the following error for the SVG bounding box
> > example on running "c:\my path...\saxon textWidthTest.xml
> > textWidthTest.xslt > output.svg" at the CMD line: Error at
> > xsl:value-of on line 17 of file:/c:/my path/textwidthtest.xslt:
> > The URI xalan://com.ora.xsltckbk.util.SVGFontMetrics does
> > not identify an external Java class Transformation failed:
> > Run-time errors were reported
> >
> > Here is the XLST and java file used:
> >
> > XSLT file
> > ------------------------------
> >
> > <?xml version="1.0" encoding="UTF-8"?>
> > <xsl:stylesheet version="1.0"
> > xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
> > xmlns:xalan="http://xml.apache.org/xslt"
> > xmlns:font="xalan://com.ora.xsltckbk.util.SVGFontMetrics"
> > exclude-result-prefixes="font xalan">
> >
> > <xsl:output method="xml"/>
> >
> > <xsl:template match="/">
> > <svg width="100%" height="100%">
> > <xsl:apply-templates/>
> > </svg>
> > </xsl:template>
> >
> >
> > <xsl:template match="text">
> > <xsl:variable name="fontMetrics" select="font:new(@font,
> > @size, boolean(@weight), boolean(@stytle))"/>
> > <xsl:variable name="text" select="."/>
> > <xsl:variable name="width" select="font:stringWidth($fontMetrics,
> > $text)"/>
> > <xsl:variable name="height" select="font:stringHeight($fontMetrics,
> > $text)"/>
> > <xsl:variable name="style">
> > <xsl:if test="@style">
> > <xsl:value-of select="concat('font-style:',@style)"/>
> > </xsl:if>
> > </xsl:variable>
> > <xsl:variable name="weight">
> > <xsl:if test="@weight">
> > <xsl:value-of select="concat('font-weight:',@weight)"/>
> > </xsl:if>
> > </xsl:variable>
> > <g style="font-family:{@font};font-size:{@size};{$style};{$weight}">
> > <!-- Use the SVGFontMetrics info render a rectangle that is -->
> > <!-- slightly bigger than the expected size of the text -->
> > <!-- Adjust the y position based on the previous text size. -->
> > <rect x="10"
> > y="{sum(preceding-sibling::text/@size) * 2}pt"
> > width="{$width + 2}"
> > height="{$height + 2}"
> > style="fill:none;stroke: black;stroke-width:0.5;"/>
> > <!-- Render the text so it is cenetered in the rectangle -->
> > <text x="11" y="{sum(preceding-sibling::text/@size) * 2 +
> > @size div 2 + 2}pt">
> > <xsl:value-of select="."/>
> > </text>
> > </g>
> >
> > </xsl:template>
> >
> >
> > </xsl:stylesheet>
> >
> >
> >
> >
> > Java class in package (xsltckbk.jar)
> > -----------------------------------------------
> >
> > package com.ora.xsltckbk.util ;
> > import java.awt.* ;
> > import java.awt.geom.* ;
> > import java.awt.font.* ;
> > import java.awt.image.*;
> >
> > public class SVGFontMetrics
> > {
> > public SVGFontMetrics(String fontName, int size)
> > {
> > m_font = new Font(fontName, Font.PLAIN, size) ;
> > BufferedImage bi
> > = new BufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB);
> > m_graphics2D = bi.createGraphics() ;
> > }
> >
> > public SVGFontMetrics(String fontName, int size, boolean
> > bold, boolean
> > italic)
> > {
> > m_font = new Font(fontName, style(bold,italic) , size) ;
> > BufferedImage bi
> > = new BufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB);
> > m_graphics2D = bi.createGraphics() ;
> > }
> >
> > public double stringWidth(String str)
> > {
> > FontRenderContext frc = m_graphics2D.getFontRenderContext();
> > TextLayout layout = new TextLayout(str, m_font, frc);
> > Rectangle2D rect = layout.getBounds() ;
> > return rect.getWidth() ;
> > }
> >
> > public double stringHeight(String str)
> > {
> > FontRenderContext frc = m_graphics2D.getFontRenderContext();
> > TextLayout layout = new TextLayout(str, m_font, frc);
> > Rectangle2D rect = layout.getBounds() ;
> > return rect.getHeight() ;
> > }
> >
> > static private int style(boolean bold, boolean italic)
> > {
> > int style = Font.PLAIN ;
> > if (bold) { style |= Font.BOLD;}
> > if (italic) { style |= Font.ITALIC;}
> > return style ;
> > }
> >
> > private Font m_font = null ;
> > private Graphics2D m_graphics2D = null;
> > }
> >
> >
> >
> >
> > I have searched the http://www.mulberrytech.com/xsl/xsl-list
> > archives, and numerous other sites for the answer, edited the
> > classpath to include "xsltckbk.jar" but to no avail.
> >
> > Any help appreciated.
> >
> >
> >
> > Linc
> >
> >
> >
> > XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
> >
>
>
> XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
>
>
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
|