xslGlobalParameterNames: Get the names of the top-level/global XSL parameters

View source: R/context.R

xslGlobalParameterNamesR Documentation

Get the names of the top-level/global XSL parameters

Description

This function allows an R function that is called (directly or indirectly) from an XSL template to query the XSL engine for the names of the top-level XSL parameters in effect. These parameters include those explicitly specified by the caller of the XSL processor as well as those defined within the XSL stylesheets. This provides one way of exploring the parameters defined in a collection of XSL stylesheets. (We can also parse the XSL document, follow the <import> and include nodes and then find the top-level <xsl:param> elements.

Usage

xslGlobalParameterNames(ctx)

Arguments

ctx

an object of clas XMLXPathParserContext. To have this object passed to our R function when it is called from XSL, our R function that is registered with XSL must be an XSLTContextFunction object.

Value

A character vector giving the names of the XSL parameters.

Author(s)

Duncan Temple Lang

See Also

registerXSLFunction xsltContextFunction

Examples

  fun =  function(ctxt, ...) {
    params = xslGlobalParameterNames(ctxt)
    vals = getXSLVariables(ctxt, params)
    print(params)
    print(vals)
    paste(params, vals, sep = " = ", collapse = ", ")
  }

  xsl = '<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
		xmlns:r="http://www.r-project.org" 
                extension-element-prefixes="r" 
                version="1.0">
           <xsl:param name="globalParam" select="1"/>
           <xsl:template match="/">
              Global Parameters: <xsl:value-of select="r:foo()"/>
           </xsl:template>
         </xsl:stylesheet>
        '  

  xml = '<article/>'

  addXSLTFunctions("foo" = xsltContextFunction(fun))

  xsltApplyStyleSheet(xml, xsl, who = "'duncan'", depth = 2L, bob = TRUE)

omegahat/Sxslt documentation built on Jan. 17, 2024, 6:44 p.m.