Re: XMLmind XSL-FO Converter : Using user-defined functions

Hussein Shafie <[email protected]>
Newsgroups gmane.text.xml.xfc.general
Message-ID <[email protected]>
On 06/26/2013 02:21 PM, Nicolas Dubien wrote:
>
> I am looking for an XLS-FO engine that can fit with my current
> architecture. I am already using other engines which are based on other
> technologies - not-XSL-FO. In our current architecture we are using
> user-defined functions to add our proper features to the engine.
>
> As a matter of fact, I was wondering if it is possible to integrate
> user-defined functions in my XSL-FO templates and define them in Java.
> Then your engine will call my Java function if necessary. I did not find
> any solutions to do this on your website.
>
> Here are examples of functions I would like to be able to call from your
> engine during the generation:
>   * getResourceUrl("my resource name")
>   * ChangeCase($first_name_from_xml, "Upper")
>   * GetId($first_name_from_xml, $last_name_from_xml)
>
> One of the engines I am using for the moment is FreeMarker, it has this
> feature. It allows developers to wrap their own objects and send them to
> their engine.
> cf.
> http://freemarker.sourceforge.net/docs/api/freemarker/template/Template.html#process%28java.lang.Object,%20java.io.Writer,%20freemarker.template.ObjectWrapper%29
>

XMLmind XSL-FO Converter is an XSL-FO processor. It starts its work 
after an intermediate XSL-FO file has been generated.

See "How it works": http://www.xmlmind.com/foconverter/how_it_works.html

The vast majority of our customers use an XSLT stylesheet to generate 
the intermediate  XSL-FO file.

An XSLT engine (which interprets the XSLT stylesheet) such as Saxon 6 
very easily supports user-defined functions written in Java.

See Saxon 6's "Writing extension functions": 
http://saxon.sourceforge.net/saxon6.5.5/extensibility.html#Writing-extension-functions

This is why there is absolutely no need for us to be able to execute 
calls to user-defined functions written in Java from our XSL-FO processor.

Example:

--> This is common and useful:

XSLT stylesheet:
---
<xsl:template match="html:img[@class='resource']">
   <fo:external-graphic src="{my:getResourceUrl('my resource name')}"
     xmlns:my="java:org.dubien.MyFunc.getResourceUrl"/>
</xsl:template>
---

which generates the following XSL-FO:
---
<fo:external-graphic src="url(file:/res/foo.png)"/>
---



--> This would be equivalent but more complex, not useful, and hence 
*not* supported.

XSLT stylesheet:
---
<xsl:template match="html:img[@class='resource']">
   <fo:external-graphic src="invoke(org.dubien.MyFunc.getResourceUrl('my 
resource name'))"/>
</xsl:template>
---

which generates the following XSL-FO:
---
<fo:external-graphic
   src="invoke(org.dubien.MyFunc.getResourceUrl('my resource name'))"/>
---

which would be then evaluated by XMLmind XSL-FO Converter as:
---
<fo:external-graphic src="url(file:/res/foo.png)"/>
---


--
XMLmind FO Converter Support List
[email protected]
http://www.xmlmind.com/mailman/listinfo/xfc-support
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.