[xsl] Using Java in XSLT to determine font metrics

Subject: [xsl] Using Java in XSLT to determine font metrics
From: "Ylvisaker, Steve" <steve.j.ylvisaker@xxxxxxxxxxxxx>
Date: Mon, 22 Dec 2008 09:37:26 -0600
This is my first attempt at calling an external Java method to do work on
behalf of
 a stylesheet. I'm not a Java developer so I think I need a fairly complete
 description of how to do this. My objective is to determine the exact length,
in pixels,
 of a given string based on the font and font size in play.

 I'm sure I have two problems here. (1) to properly bind my stylesheet to a
Java name
 space and (2) proper use of the Java methods that parse my font and return
 metrics I'm looking for.

 Following is my failed stylesheet, annotated with comments explaining what I
 "trying" to do at each step. I am very certain that I am not properly telling
 which font I am using.

 I am working within the <oXygen/> IDE (Saxon8) and have successfully gotten
the example on
 page 134 of Michael's XSLT 2.0 3rd Edition to work. This tells me that I am
 successful in using Java extensions.

 When I process this stylesheet I get the following error:
 Cannot find a matching 0-argument function named

 Unfortunately this error message doesn't tell me if the problem is that I'm
not finding
 the Java method or if I'm finding it but not using it properly.

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
    <xsl:output indent="yes"/>
<xsl:template match="/">
    <xsl:variable name="tstString" select="'Hello World'"/>

<!-- declair a font and fontsize - not shure who is listening to this -->
    FontMetrics:Font("helveticaWorld", Font.PLAIN, 10)

<!-- obtain the metrics for the specified font -->
    <xsl:variable name="metrics">
        <xsl:value-of select="FontMetrics:getFontMetrics()"/>

<!-- obtain the length in pixels of the test string -->
    <xsl:variable name="resultStringLength">
         <xsl:value-of select="metrics.stringWidth($tstString)"/>

<!-- display the result -->



Thanks in advance for you help. Please keep in mind that I am not a Java
developer at all
so nothing is obvious to me.

Steve Ylvisaker


Information transmitted by this email is
proprietary to Medtronic and is intended for use only by the individual or
entity to which it is addressed, and may contain information that is private,
privileged, confidential or exempt from disclosure under applicable law. If
you are not the intended recipient or it appears that this mail has been
forwarded to you without proper authority, you are notified that any use or
dissemination of this information in any manner is strictly prohibited. In
such cases, please delete this mail from your records.
To view this notice
in other languages you can either select the following link or manually copy
and paste the link into the address bar of a web browser:

Current Thread