Re: [xslt] extending xsltproc with plugins



On Fri, Jan 11 2008 07:46:55 +0000, gr active-media-group com wrote:
> I have to extend xsltproc with a set of our defined funcion and as I'm not a 
> pro c programmer (as I'm a java programmer) I'm not able to compile my 
> library file against the source code of libxslt. I try to compile it with the 
> whole libxslt, adding some lines (maybe in the wrong way) to the make file 
> but there's no way to compile it.

Presumably your project would use the GNU Autotools with a 'configure'
script, etc.

Here's an extract from a 'Makefile.am' that I've used in the past (where
the extensions used GLib):

------------------------------------------------------------
## Process this file with automake to produce Makefile.in

INCLUDES = \
	-DMODULE_COMPILE	\
	$(LIBEXSLT_CFLAGS)	\
	$(GLIB_CFLAGS) -Wall

LDADDS = @STRIP_BEGIN@	\
	@GLIB_LIBS@	\
@STRIP_END@

plugindir = @LIBXSLT_PLUGINS_DIR@
plugin_LTLIBRARIES = example_com_plugin.la

example_com_plugin_la_SOURCES = \
	extensions.c
example_com_plugin_la_LDFLAGS = \
	-module -avoid-version -rpath $(plugindir)
example_com_plugin_la_LIBADD = \
	$(LIBEXSLT_LIBS)	\
	$(GLIB_LIBS)
------------------------------------------------------------

where (paraphrasing my 'configure.ac') LIBXSLT_PLUGINS_DIR is defined
using:

   LIBXSLT_PLUGINS_DIR=`xslt-config --plugins`
   AC_SUBST(LIBXSLT_PLUGINS_DIR)

> I see that the make don't compile the testplugin.c file. So I can't even try 

testplugin.c is compiled when you run 'make tests'.

> to put this example file in /usr/local/lib/libxslt-plugins/ folder. 
> Can somebody help me please?
> Another question, having a look (more than one for real) at the source code of 
> TestPlugin.c there's this comment
>
> function libxslt:test() for testing the extensions support.
>
> but in the test xslt file this is the call to the function and the element:
>
> <libxslt:testplugin/>
> <xsl:value-of select="libxslt:testplugin('SUCCESS')"/>
>
> Is anything I miss or is an error in the documentation?

The mapping of XSLT extension element and function names and namespaces
to C functions in testplugin.c is in xmlsoft_org_xslt_testplugin_init()
[1]:

------------------------------------------------------------
    xsltRegisterExtModuleFunction((const xmlChar *) "testplugin",
                                  (const xmlChar *) XSLT_TESTPLUGIN_URL,
                                  xsltExtFunctionTest);
    xsltRegisterExtModuleElement((const xmlChar *) "testplugin",
                                 (const xmlChar *) XSLT_TESTPLUGIN_URL,
                                 xsltExtElementPreCompTest,
                                 xsltExtElementTest);
------------------------------------------------------------

> Another question, should the library and the function inside the library (our 
> function not the one to load an unload the library in xsltproc) respect any 
> kind of naming convention? I ask this because I see some example around where 
> if the namespace is www.test.xml/test the library is called test_xml_test.so.

There's nothing special about the C function name.  Of course, it's
easier for people to make the association if the C function name has
some resemblance to the XSLT element or function name.

The name of the extension library *is* significant for dynamic plugins.

>From the comment in extensions.c [2]:

------------------------------------------------------------
/**
 * xsltExtModuleRegisterDynamic:
 * @URI:  the function or element namespace URI
 *
 * Dynamically loads an extension plugin when available.
 * 
 * The plugin name is derived from the URI by removing the 
 * initial protocol designation, e.g. "http://";, then converting
 * the characters ".", "-", "/", and "\" into "_", the removing
 * any trailing "/", then concatenating LIBXML_MODULE_EXTENSION.
 * 
 * Plugins are loaded from the directory specified by the 
 * environment variable LIBXSLT_PLUGINS_PATH, or if NULL, 
 * by LIBXSLT_DEFAULT_PLUGINS_PATH() which is determined at
 * compile time.
 *
 * Returns 0 if successful, -1 in case of error. 
 */
------------------------------------------------------------

Plus you need to use "extension-element-prefixes" in your stylesheet
even when you're using only extension functions [3]:

   Registration of new functions or elements are bound to the activation
   of the module. This is currently done by declaring the namespace as
   an extension by using the attribute extension-element-prefixes on the
   xsl:stylesheet element.

Regards,


Tony Graham.
======================================================================
Tony Graham MenteithConsulting com   http://www.menteithconsulting.com

Menteith Consulting Ltd             Registered in Ireland - No. 428599
Registered Office: 13 Kelly's Bay Beach, Skerries, Co. Dublin, Ireland
----------------------------------------------------------------------
Menteith Consulting -- Understanding how markup works
======================================================================

[1] http://svn.gnome.org/viewvc/libxslt/trunk/tests/plugins/testplugin.c?view=markup
[2] http://svn.gnome.org/viewvc/libxslt/trunk/libxslt/extensions.c?view=markup
[3] http://www.xmlsoft.org/XSLT/extensions.html#Keep


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]