|
Subject: RE: [xsl] XSLT extention problem From: "Michael Kay" <mike@xxxxxxxxxxxx> Date: Wed, 5 Dec 2007 09:49:06 -0000 |
I notice that the spec of
public ImageIcon(String filename)
says: When specifying a path, use the Internet-standard forward-slash ("/")
as a separator.
whereas you are doing the opposite:
path.replace("/", File.separator)
I've no idea if that's relevant to your problems.
Incidentally, this code:
<xsl:for-each select="@*">
<xsl:if test="not(name(.)='WIDTH' or name(.)='HEIGHT')">
<xsl:apply-templates select="."/>
</xsl:if>
</xsl:for-each>
can be rewritten as
<xsl:apply-templates select="@* except (@WIDTH, @HEIGHT)"/>
(or just select="@*", with the addition of a do-nothing template to match
@WIDTH and @HEIGHT).
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: [xsl] 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 > $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 |
|---|
|
| <- Previous | Index | Next -> |
|---|---|---|
| RE: [xsl] XSLT extention problem, Michael Kay | Thread | Re: [xsl] XSLT extention problem, jingjun long |
| RE: [xsl] XSLT extention problem, Michael Kay | Date | Re: [xsl] XSLT extention problem, jingjun long |
| Month |