views:

548

answers:

2

I am copying an example from XSLT Cookbook: 2nd Edition (O'Reilly: Mangano, 2006) where Mangano creates a tree diagram with SVG. As a way to quickly test this code, I am simply transforming the XML using JSTL's <x:transform/> tag, and running it in Jetty 6. The XSLT seems to be getting hung on calling java:java.lang.Math:max, saying:

ERROR: 'Cannot find external method 'max' (must be public).' FATAL ERROR: 'Could not compile stylesheet'

The code that gives me the error is contained in here where ...Math:max(... is called:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.1"
       xmlns:emath="http://www.exslt.org/math"
       xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
       xmlns:tree="http://www.ora.com/XSLTCookboox/ns/tree"
       xmlns:xalan="http://xml.apache.org/xslt"
       xmlns:Math="xalan:java.lang.Math">
...
<!--Pass 1 copies input with added bookkeeping attributes -->  
<xsl:variable name="treeWithLayout">
  <xsl:apply-templates mode="layout"/>
</xsl:variable>

<xsl:variable name="maxPos" 
      select="Math:max($treeWithLayout/*/@tree:WEIGHT * 
                       ($nodeWidth + $horzSpace),
                       $treeWithLayout/*/@tree:MAXDEPTH * 
                         ($nodeHeight + $vertSpace))"/>
...
A: 

I found this usage online:

<xsl:stylesheet version="1.0" 
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:math="xalan://java.lang.Math"
  extension-element-prefixes="math">
Allain Lalonde
Thanks. I updated the math namespace to use "xalan://", and proved that Math does work. The problem remains that something inside of "Math:max($treeWithLayout/*/@tree:WEIGHT * ($nodeWidth + $horzSpace),$treeWithLayout/*/@tree:MAXDEPTH * ($nodeHeight + $vertSpace))" is causing the problem...
Matt Fisher
Thanks...the xalan:// is what I needed. Although, I soon had to move to Saxon for XSLT 2.0 support.
Matt Fisher
A: 

Hi, I am trying to use XSLT, similar to the situation above. My XSLT runs fine when i run my code through eclipse, but when I try to run the application from command line, it throws the same error you got above - "External method must be public". The error occurs with or without "xalan://" Any ideas? Also, the error occurs in both XSLT 1.0 and XSLT 2.0...