Hi Chris,
Not standard EXSLT functions, but I have loaded extension functions under 2.1.
I’ve just consulted my archives (2006!)…
Firstly, I used a .xweb patch file patch Cocoon’s servlet configuration, in
order to pre-load my extension classes using Cocoon's load-class init-param;
this was because doing it lazily at run-time created a class-loader
race-condition under high load, which caused a random extension class to be
called on production, and thus randomly fail with a NoSuchMethod exception,
which was perplexing to say the least (so I mention this so you don’t have the
same problem!):
<?xml version="1.0" encoding="UTF-8"?>
<xweb
xpath="/web-app/servlet[servlet-name='Cocoon']/init-param[param-name='load-class']/param-value"
remove="/web-app/servlet[servlet-name='Cocoon']/init-param[param-name='load-class']/param-value/text()"
>
<!-- pre-load classes used as XSLT extensions to prevent classloader
race-condition under high load -->
com.xxx.xml.exslt.Dates
com.xxx.xml.exslt.FileUtils
</xweb>
etc.
This goes into cocoon's src/confpatch directory as e.g. load-class.xweb and
patches web.xml, unless you build it some other way.
Then you just write a simple POJO with static methods to do your functionality,
e.g. I had a little function for finding a local file-size:
package com.xxx.xml.exslt;
import java.io.File;
public class FileUtils {
/**
* returns the size of a file rounded to the nearest Kilobyte.
* @param fileName
* @return the file size in KB, or 0 if file not accessible.
*/
public static long Size(String fileName) {
File file = new File(fileName);
return ((file.length()+512)/1024);
}
}
Then to use this from the XSL, you just declare a namespace with the full class
name as the URI, and use the prefix and method name as you would use any other
function e.g.:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:file=“com.xxx.xml.exslt.FileUtils”>
<xsl:template match=“something”>
Size = <xsl:value-of select="file:Size($path)"/>
</xsl:template>
</xsl:stylesheet>
Hope that works for you: it’s been a long long time since I did anything
Cocoony...
Ellis.
On 27 Feb 2014, at 21:47, Christopher Schultz <[email protected]>
wrote:
> Signed PGP part
> All,
>
> I've been successfully using EXSLT functions -- specifically, the
> date-and-time functions (http://exslt.org/date/index.html) -- for some
> years now and I was interested in using the "seconds" function. It
> turns out that the "seconds" function is not in the core functions and
> so for whatever reason, it's not been included in Xalan (I'm using
> Cocoon 2.1.11 which uses Xalan 2.7.1 by default).
>
> I've tried to download and use the date.seconds.xsl template and
> included Javascript and MSXML XSL templates with a mixture of
> <xsl:import> and xmlns:date declarations, but nothing seems to get the
> two working together.
>
> Has anyone ever manually-plugged an EXSLT function into Xalan? How did
> you do it?
>
> Thanks,
> -chris
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [email protected]
> For additional commands, e-mail: [email protected]
>
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]