Description Usage Arguments Value Note Author(s) References See Also Examples
This function and methods are intended to help understand and debug XSL processing by allowing the caller to query which XSL template will be used to process a particular node.
There are several different methods which attempt to make it both convenient and efficient to invoke. One can specify the style sheet and node by name, i.e. a URL for the style sheet document and a string giving the name of the node of interest. Alternatively, one can parse the style sheet and pass this internal representation. If one is querying multiple templates within the same style sheet, this avoids re-parsing the style sheet each time.
When dealing with nodes with name spaces, you create the
XMLInternalNode
, e.g. via newXMLNode
, and give it the
name space definitions. Alternatively, you can take a node from an
existing XML document.
Finally, in the process of an XSL transformation, an R function
which has a reference to the
XMLXPathParserContext-class
object for that XSL
transformation can get the template for an arbitrary node
from that XSL context which has access to the style sheet in effect.
1 | getTemplate(ctxt, node, mode = character())
|
ctxt |
the object that identifies the XSL style sheet. This can
be one of several different types of object. It can be a URL/file
name of style sheet, a pre-parsed style sheet, an
XMLInternalDocument obtained by reading the XSL document into R
(using |
node |
an object identifying the XML node whose corresponding
applicable template is to be found in the style sheet.
This can be a string giving the node name or an actual internal
node of class |
mode |
a character string specifying the XSL mode to use when looking
for the template. This allows us to emulate how XSL transformations work
via |
The basic return value is an object of class
XSLTemplateDescription-class
. If the parsed style
sheet was not supplied by the user, an object of class
XSLCopiedTemplateDescription
is returned which has certain
fields converted to an R representation rather than left as
references to C-level data structures that will be garbage
collected. XSLCopiedTemplateDescription-class
is a
"sub-class" of XSLTemplateDescription-class
. Both of
these classes are currently in S3-style form.
We could copy the node and style sheet when it would be garbage collected but it is not clear how people will want to use this information, e.g. apply a template.
Duncan Temple Lang
~put references to the literature/web site here ~
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# A query to see which template handles article.
#XXX Problem
temp = getTemplate("http://www.omegahat.org/XDynDocs/XSL/html.xsl", "article")
# Query a node with a name space so have to create the node
# (The node does get copied as it has no document which is needed
# during the creation of the XSL context)
library(XML)
node = newXMLNode("r:code", namespaceDefinitions = c(r = "http://www.r-project.org"))
rcode = getTemplate("http://www.omegahat.org/XDynDocs/XSL/html.xsl", node)
rcode
docName(rcode)
rcode$location
cat(rcode$node)
# Instead of parsing the style sheet each time, do it once and do
# multiple queries
html.sty = xsltParseStyleSheet("http://www.omegahat.org/XDynDocs/XSL/html.xsl")
rcode = getTemplate(html.sty,
newXMLNode("r:code", namespaceDefinitions = c(r = "http://www.r-project.org")))
templates = lapply(c("latex", "docbook", "ulink"), function(x) getTemplate(html.sty, x))
sapply(templates, docName)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.