registerXSLFunction: Define an XSL extension function

Description Usage Arguments Details Value Author(s) References See Also Examples

View source: R/register.S

Description

This function provides a way to define an XSL function that is implemented using an R function. The XSL function is immediately available to the XSLT engine. This should only be called during the initialization of the XSLT module (or during the evaluation of one of the R functions exported to the XSLT module). It is not used in between the application of XSL sheets. To “queue” functions to be registered with the XSLT engine when the module is initialized, use addXSLTFunctions rather than this one.

Usage

1
2
registerXSLFunction(name, fun, symbol=NULL, uri= RExtensionNamespace,
                    old=FALSE, context = NULL)

Arguments

name

the name to use for the XSL function being defined. This is how it will be addressed/referenced in the XSL stylesheets.

fun

a function object, the name of a function or a string that is an S expression that evaluates to a function object. If this is not supplied, we use the function named name.

symbol

the name of a C routine to use as the implementation of the XSL function name. Either fun or symbol is usually specified, not both.

uri

the URI identifying the XSL namespace for this XSL function. This specifies how the XSL code addresses the function. The namespace and URI should be declared in the XSL document.

old

a logical value indicating whether the previous function or symbol associated with this XSL function name should be returned or not. This allows the function to be easily called from XSL (the register function) without having to deal with complicated conversion of an R object to an XSL value.

context

the XSLT parsing context that is passed as the second argument to the initialization function.

Details

This stores the S function in an internal table under the index name and registers the XSL function name with the XSLT engine along with a C routine that is a generic R function handler. When the XSL function is called, the XSLT engine calls that C routine which retrieves the associated R function from the internal table and calls it with the arguments from the XSL stack.

Value

If old is FALSE, this returns a logical value indicating whether the function was registered or not. If old is TRUE, the R function or C symbol that was previously registered (if any) will be returned.

Author(s)

Duncan Temple Lang

References

http://www.omegahat.org/Sxslt, http://www.omegahat.org/SXalan, http://www.w3.org/Style/XSL

See Also

addXSLTFunctions

register.xsl, register.xml and register.R in the examples directory.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
## Not run: 
  registerXSLFunction("init", function(...) { TRUE })
  registerXSLFunction("register", function(name, func) { TRUE })
  registerXSLFunction("foo", function(x) { cat("in foo\n"); print(x) ; x*2})
  registerXSLFunction("bar", function(x,y) { cat("in bar\n"); print(x) ; print(y) ; nchar(x) + nchar(y)})

  xsltApplyStyleSheet(system.file("examples", "register.xml", package = "Sxslt"),
                      system.file("examples", "register.xsl", package = "Sxslt"), FALSE)

## End(Not run)

sckott/sxslt documentation built on May 26, 2017, 3:49 a.m.