You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cocoon.apache.org by Derek Hohls <DH...@csir.co.za> on 2004/11/22 07:16:14 UTC

[SOLVED] Re: Extension functions in XSL (Saxon)

Thanks Norman;

For Xalan (Cocoon) I have used 

  xmlns:java="http://xml.apache.org/xalan/java"
  exclude-result-prefixes="java"  

in my root stylesheet element, and  then

 select="java:java.lang.Math.max($num1,$num2)

This seems to work fine.  I am not sure about a 
more generic solution?

Derek

>>> normanb@comsine.co.uk 2004/11/19 02:00:49 PM >>>
Derek Hohls wrote:

>I am running Cocoon 2.1.5 under Windows XP, Java 1.4.2
>
>I have the following test files:
>
>math.xml
><?xml version="1.0" encoding="UTF-8"?>
><root>
>  <number>42</number>
></root>
>
>math.xsl
><?xml version="1.0"?> 
><xsl:stylesheet
>  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
>  xmlns:math="java:java.lang.Math"
>  version="1.0">
>
><xsl:template match="/">
>  <xsl:value-of  select="math:max(5,10)"/>
>  *
>  <xsl:value-of  select="math:cos(100)"/>
></xsl:template>
> 
></xsl:stylesheet>  
>
>when I run this through Saxon  on the command line,
>I get :
>
>test.xml
><?xml version="1.0" encoding="utf-8"?>10
>*
>0.8623188722876839
>
>but when I try the same process under Cocoon, I get:
>
>org.apache.cocoon.ProcessingException: Failed to execute pipeline.:
>java.lang.RuntimeException: java.lang.NoSuchMethodException: For
>extension function, could not find method
>java.lang.Double.max([ExpressionContext,] #NUMBER).
>
>Any ideas how to get extension functions like this to work?
>
>Thanks
>Derek
>
>  
>
I think because in Cocoon you are using Xalan, you can do it this way

xmlns:math="http://exslt.org/math"

and then declaring 
<xsl:value-of  select="math:max(5,10)"/>

will work.

Alternative you can use the namespace
xmlns:math="xalan://java.lang.Math"

which will allow you to use the java functions.

The former is preferable as it is not dependent on
the stylesheet processor.

Norman

-- 
Norman Barker
Software Engineer
ComSine Ltd
Tel: +44 (0)1483 457121
Web: http://www.comsine.com 
*Please Note:*
This text is confidential. If you are not the named addressee, it could
be unlawful for you to read, copy, distribute, disclose or use the
information contained herewith. If you are not the intended recipient
please telephone +44(0)1483 457121.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org 
For additional commands, e-mail: users-help@cocoon.apache.org 


-- 
This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.
MailScanner thanks transtec Computers for their support.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org