Learn R Programming

xslt (version 0.0.0.9002)

xslt_transform: Transform an XML document with an XSLT stylesheet

Description

Transform an XML document with an XSLT stylesheet

Usage

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

Run this code
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))

Run the code above in your browser using DataLab