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

Description Usage Arguments Value Author(s) See Also Examples

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

1

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

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
  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)

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