xslt_transform: Transform an XML document with an XSLT stylesheet

Description Usage Arguments Value Examples

Description

Transform an XML document with an XSLT stylesheet

Usage

1
xslt_transform(xml_doc, xslt_doc, is_html = FALSE, fix_ns = FALSE)

Arguments

xml_doc

an XML or HTML document (either a string with XML/HTML, a filename or URL pointing to a file wiht XML/HTML). This can also be the result of a value returned from xml2::read_xml or xml2::read_html, thus enabling it to be used in pipelines.

xslt_doc

an XSLT document (either a string with XML/XSLT, a filename or URL pointing to a file wiht XML/XSLT). This can also be the result of a value returned from xml2::read_xml or xml2::read_html.

is_html

is xml_doc really an HTML? If so, set this (default FALSE)

fix_ns

intercourse the namespaces (highly useful for HTML processing - default FALSE)

Value

Either objects comparable to xml2::read_xml or xml2::read_html (if the XSLT output method was xml or html respectively) or a single-element character vector with the transformed document text.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
library(xml2)
library(xslt)

xml_src <- "<test/>"
xslt_src <- '<xsl:stylesheet version="1.0"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

  <xsl:template match="/">
    <article>
      <title>Hello World</title>
    </article>
  </xsl:template>
</xsl:stylesheet>'

doc <- read_xml(xml_src)
xsl <- read_xslt(xslt_src)

res <- xslt_transform(doc, xsl)
cat(as.character(res))

res <- xslt_transform(xslt_src, xslt_src)
cat(as.character(res))

hrbrmstr/xslt documentation built on May 17, 2019, 5:54 p.m.