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

RE: XSLT extention problem

Subject: RE: XSLT extention problem
From: "Michael Kay" <mike@xxxxxxxxxxxx>
Date: Wed, 5 Dec 2007 09:38:15 -0000
RE:  XSLT extention problem
Can't think of any obvious reason for the problem. I'm a bit surprised to
see a Swing class being called from an extension function though; there
could be some kind of problem with methods being called in the wrong order
and the environment not being properly initialized. Or it could simply be
that you're doing filestore access with the wrong current directory set.

Michael Kay
http://www.saxonica.com/ 

> -----Original Message-----
> From: jingjun long [mailto:longjingjun@xxxxxxxxx] 
> Sent: 05 December 2007 07:09
> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Subject:  XSLT extention problem
> 
> hi there,
> 
> I am writing an Java extention for my XSLT.
> 
> There are two static method in the java code, there are:
> 
> int getHeight(String path);
> int getWidth(String path);
> 
> 
> package com.atomsoft.app.graphictools;
> 
> import java.io.File;
> 
> import javax.swing.ImageIcon;
> 
> public class GraphicInfo
> {
> public static int getWidth(String path)
> {
> int width = 0;
> 
> String temp_path = path.replace("/", File.separator); 
> temp_path = temp_path.substring(6);
> 
> ImageIcon icon = new ImageIcon(temp_path); width = 
> icon.getIconWidth();
> 
> return width;
> }
> 
> public static int getHeight(String path) { int height = 0;
> 
> String temp_path = path.replace("/", File.separator); 
> temp_path = temp_path.substring(6);
> 
> ImageIcon icon = new ImageIcon(temp_path); height = 
> icon.getIconHeight();
> 
> return height;
> }
> }
> 
> 
> The following is my XSLT:
> 
> <?xml version="1.0" encoding="utf-8"?>
> 
> <xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
> xmlns:xs="http://www.w3.org/2001/XMLSchema"
> xmlns:atomExt="com.atomsoft.app.graphictools.GraphicInfo"
> version="2.0">
> 
> <xsl:param name="max_width" select="500"/>
> 
> <xsl:output method="xml" encoding="UTF-8" indent="yes"/>
> 
> <xsl:template match="SHEET">
> <xsl:element name="{name()}">
> <xsl:variable name="v_filepath" select="unparsed-entity-uri(@GNBR)"/>
> <xsl:variable name="v_org_width" 
> select="atomExt:getWidth($v_filepath)"/>
> <xsl:variable name="v_org_height" 
> select="atomExt:getHeight($v_filepath)"/>
> 
> 
> <xsl:variable name="v_new_width">
> <xsl:choose>
> <xsl:when test="$v_org_width &gt; $max_width"><xsl:value-of 
> select="$max_width"/></xsl:when> <xsl:otherwise><xsl:value-of 
> select="$v_org_width"/></xsl:otherwise>
> </xsl:choose>
> </xsl:variable>
> 
> <xsl:variable name="v_new_height" select="round($v_org_height 
> * $v_new_width div $v_org_width)"/>
> 
> <xsl:attribute name="WIDTH" select="$v_new_width"/> 
> <xsl:attribute name="HEIGHT" select="$v_new_height"/>
> 
> <xsl:for-each select="@*">
> <xsl:if test="not(name(.)='WIDTH' or name(.)='HEIGHT')"> 
> <xsl:apply-templates select="."/> </xsl:if> </xsl:for-each>
> 
> <xsl:apply-templates select="*"/>
> 
> 
> </xsl:element>
> 
> 
> </xsl:template>
> 
> <xsl:template match="*">
> <xsl:element name="{name()}">
> <xsl:apply-templates select="@*|node()"/> </xsl:element> 
> </xsl:template>
> 
> <xsl:template match="@*">
> <xsl:attribute name="{name()}">
> <xsl:value-of select="."/>
> </xsl:attribute>
> </xsl:template>
> 
> </xsl:transform>
> 
> 
> 
> The xslt works. My problem is:
> I tested the java code stand alone. It works fine. But when I 
> call the java method in my XSLT, The result file is generated 
> but the xslt command line is hanged.
> 
> It seems this problem have something to do the following java code:
> 
> ImageIcon icon = new ImageIcon(temp_path); height = 
> icon.getIconHeight();
> 
> If I do not use this class (ImageIcon), it works fine in 
> XSLT. Is there some special thing in this class?
> 
> I am using Saxon 8.9 as my XSLT engine.
> 
> Thanks
> 
> Jingjun

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.