Coder Social home page Coder Social logo

xslt's Introduction

xslt

XSLT 1.0 Transformations

Project Status: Active – The project has reached a stable, usable state and is being actively developed. CRAN_Status_Badge CRAN RStudio mirror downloads

An extension for the 'xml2' package to transform XML documents by applying an XSL stylesheet.

Usage

Basic example included with the package:

doc <- read_xml(system.file("examples/cd_catalog.xml", package = "xslt"))
style <- read_xml(system.file("examples/cd_catalog.xsl", package = "xslt"))
html <- xml_xslt(doc, style)
cat(as.character(html))

xslt's People

Contributors

jeroen avatar jimhester avatar maelle avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Forkers

jimhester

xslt's Issues

encoding bug?

stylesheet <- xml2::read_xml("https://raw.githubusercontent.com/ropenscilabs/tinkr/master/inst/extdata/xml2md.xsl")
doc <- readLines("https://raw.githubusercontent.com/ropensci/roweb2/master/content/blog/2013-11-21-rgbif-changes.md",
                 encoding = "UTF-8")
doc <- commonmark::markdown_xml(doc)
doc <- xml2::read_xml(doc)
output <- xslt::xml_xslt(doc, stylesheet)
regmatches(output, regexpr(".partements", output))
#> [1] "©partements"
regmatches(toString(doc), 
           regexpr(".partements", toString(doc)))
#> [1] "épartements"

Created on 2018-09-17 by the reprex package (v0.2.0).

Error installing `xslt`

Hit the following error whilst trying to install xslt under an renv...

- Installing xslt ...                           FAILED
Error: Error installing package 'xslt':
================================

* installing *source* package ‘xslt’ ...
** using staged installation
Found pkg-config cflags and libs!
Using PKG_CFLAGS=-I/usr/include/libxml2
Using PKG_LIBS=-lexslt -lxslt -lxml2
** libs
using C++ compiler: ‘g++ (GCC) 13.2.1 20230801’
rm -f RcppExports.o xslt.o xslt_init.o xslt.so
g++ -std=gnu++17 -I"/usr/include/R/" -DNDEBUG -I/usr/include/libxml2 -DSTRICT_R_HEADERS -I'/home/neil/work/git/hub/ns-rse/git-collaboration/renv/staging/1/Rcpp/include' -I'/home/neil/work/git/hub/ns-rse/git-collaboration/renv/staging/1/xml2/include' -I/usr/local/include    -fpic  -O3 -Wall -pedantic -march=native -mtune=native -pipe -c RcppExports.cpp -o RcppExports.o
g++ -std=gnu++17 -I"/usr/include/R/" -DNDEBUG -I/usr/include/libxml2 -DSTRICT_R_HEADERS -I'/home/neil/work/git/hub/ns-rse/git-collaboration/renv/staging/1/Rcpp/include' -I'/home/neil/work/git/hub/ns-rse/git-collaboration/renv/staging/1/xml2/include' -I/usr/local/include    -fpic  -O3 -Wall -pedantic -march=native -mtune=native -pipe -c xslt.cpp -o xslt.o
g++ -std=gnu++17 -I"/usr/include/R/" -DNDEBUG -I/usr/include/libxml2 -DSTRICT_R_HEADERS -I'/home/neil/work/git/hub/ns-rse/git-collaboration/renv/staging/1/Rcpp/include' -I'/home/neil/work/git/hub/ns-rse/git-collaboration/renv/staging/1/xml2/include' -I/usr/local/include    -fpic  -O3 -Wall -pedantic -march=native -mtune=native -pipe -c xslt_init.cpp -o xslt_init.o
xslt_init.cpp: In function ‘void R_init_xslt(DllInfo*)’:
xslt_init.cpp:36:37: error: invalid conversion from ‘void (*)(void*, xmlError*)’ {aka ‘void (*)(void*, _xmlError*)’} to ‘xmlStructuredErrorFunc’ {aka ‘void (*)(void*, const _xmlError*)’} [-fpermissive]
   36 |     xmlSetStructuredErrorFunc(NULL, handleError);
      |                                     ^~~~~~~~~~~
      |                                     |
      |                                     void (*)(void*, xmlError*) {aka void (*)(void*, _xmlError*)}
In file included from xslt_init.cpp:4:
/usr/include/libxml2/libxml/xmlerror.h:898:57: note:   initializing argument 2 of ‘void xmlSetStructuredErrorFunc(void*, xmlStructuredErrorFunc)’
  898 |                                  xmlStructuredErrorFunc handler);
      |                                  ~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~
make: *** [/usr/lib64/R/etc/Makeconf:200: xslt_init.o] Error 1
ERROR: compilation failed for package ‘xslt’
* removing ‘/home/ns-rse/work/git/hub/ns-rse/git-collaboration/renv/staging/1/xslt’
install of package 'xslt' failed [error code 1]
Traceback (most recent calls last):
12: renv::install("sandpaper")
11: renv_install_impl(records)
10: renv_install_staged(records)
 9: renv_install_default(records)
 8: handler(package, renv_install_package(record))
 7: renv_install_package(record)
 6: withCallingHandlers(renv_install_package_impl(record), error = function(e) writef("FAILED"))
 5: renv_install_package_impl(record)
 4: r_cmd_install(package, path)
 3: r_exec_error(package, output, "install", status)
 2: abort(all)
 1: stop(fallback)

EDIT : This happens at the system level as well as when installing under a renv with both R-4.3.2 and R-4.3.3.

Request: create release for latest version

The latest release on this repository is listed as 1.2, but on CRAN, it's 1.4.3, which I believe corresponds to this commit: 8eadf93
Would you be able to create a release that points to this commit (or whichever one corresponds to the version on CRAN)?

Background

I use the releases (and not default branch) from github to build my r-universe for three reasons:

  1. binaries are built sooner than CRAN when packages like stringi get released
  2. the API for the system dependencies is far quicker than iterating with {remotes} or {pak}
  3. to ensure there is a reasonable fallback for {renv} environments

xpath document()

I am trying to transform an XML file through the use of an XSLT so as to obtain a CSV through the use of xml_xslt () with these commands:

library(xslt)
library(xml2)

xmlNid <- as.character(8164)
xslObs.url <- "http://www.get-it.it/objects/sensors/xslt/EMF2CSVObs.xsl"
xmlObs <- paste0("https://data.lter-europe.net/deims/node/", xmlNid,"/emf")
style <- read_xml(xslObs.url, package = "xslt")
doc <- read_xml(xmlObs, package = "xslt")
outputCsv <- xml_xslt(doc, style)

The result are the following with warnings:

Title;TitleURL;Metadata;MetadataURL;GetData;GetDataURL\n
;https://data.lter-europe.net/deims/node/8932;ISO19139 (GMD);https://data.lter-europe.net/deims/node/8932/iso19139;Other data type;\n
;https://data.lter-europe.net/deims/node/8881;ISO19139 (GMD);https://data.lter-europe.net/deims/node/8881/iso19139;Other data type;\n
;https://data.lter-europe.net/deims/node/8882;ISO19139 (GMD);https://data.lter-europe.net/deims/node/8882/iso19139;Other data type;\n

Warning messages:
1: In doc_xslt_apply(doc$doc, stylesheet$doc, paramstr) :
  failed to load external entity "https://data.lter-europe.net/deims/node/8932/iso19139" [1549]
2: In doc_xslt_apply(doc$doc, stylesheet$doc, paramstr) :
  failed to load external entity "https://data.lter-europe.net/deims/node/8932/iso19139" [1549]
3: In doc_xslt_apply(doc$doc, stylesheet$doc, paramstr) :
  failed to load external entity "https://data.lter-europe.net/deims/node/8881/iso19139" [1549]
4: In doc_xslt_apply(doc$doc, stylesheet$doc, paramstr) :
  failed to load external entity "https://data.lter-europe.net/deims/node/8881/iso19139" [1549]
5: In doc_xslt_apply(doc$doc, stylesheet$doc, paramstr) :
  failed to load external entity "https://data.lter-europe.net/deims/node/8882/iso19139" [1549]
6: In doc_xslt_apply(doc$doc, stylesheet$doc, paramstr) :
  failed to load external entity "https://data.lter-europe.net/deims/node/8882/iso19139" [1549]

I have also tested XSLT on oXygen and the result is this:

Title;TitleURL;Metadata;MetadataURL;GetData;GetDataURL
Biovolume of Phytoplankton in Lake Maggiore site code IT_SI001137_within the period 1981-2010;https://data.lter-europe.net/deims/node/8932;ISO19139 (GMD);https://data.lter-europe.net/deims/node/8932/iso19139;Other data type;ftp://[email protected]/KnownUsers/2253_2/EnvEurope_DataCollection/
IT_SI001137_airTEMP 250513 Data on air temperature in Lake Maggiore 2011-2012;https://data.lter-europe.net/deims/node/8881;ISO19139 (GMD);https://data.lter-europe.net/deims/node/8881/iso19139;Other data type;ftp://[email protected]/KnownUsers/2253_2/EnvEurope_DataCollection/
IT_SI001137_PREC 250513 Data on precipitation in Lake Maggiore 2011-2012;https://data.lter-europe.net/deims/node/8882;ISO19139 (GMD);https://data.lter-europe.net/deims/node/8882/iso19139;Other data type;ftp://[email protected]/KnownUsers/2253_2/EnvEurope_DataCollection/

Could be a problem about HTTPS connection? Any other solution?

Best regards
Alessandro

Unable to run second transformation without saving first result to disk

To transform a KML file for data frame build, I attempted back-to-back calls of xml_xslt() which does not yield correct result and does not raise any error. Oddly, only the root node outputs.

However, saving first transformation to disk with xml2::write_xml followed by xml2::read_xml and then run a second xml_xslt does output the correct, desired result. See below reproducible example with source files.

Can issue involve the default KML namespace handling? Outputs of read_xml and xml_xslt both return xml_document types. My XSLT 1.0 scripts are fully compliant, validated with Linux's xsltproc and with online fiddle.

R (see differences in final_doc)

library(xml2)
library(xslt)

# DOWNLOAD KML FILE
tmp <- tempfile()
download.file(
  paste0(
    "https://data.cityofchicago.org/download/rytz-fq6y/",
    "application%2Fvnd.google-earth.kmz"
  ),
  destfile = tmp,
  mode = "wb"
)
unzip(tmp, files = "doc.kml")
unlink(tmp)
# trying URL 'https://data.cityofchicago.org/download/rytz-fq6y/application%2Fvnd.google-earth.kmz'
# downloaded 648 KB

# READ XML AND XSLT
doc <- read_xml("doc.kml", package = "xslt")
style1 <- read_xml("style1.xsl", package = "xslt")
style2 <- read_xml("style2.xsl", package = "xslt")

# BACK TO BACK TRANSFORMATIONS
new_doc <- xml_xslt(doc, style1)
final_doc <- xml_xslt(new_doc, style2)

final_doc
# {xml_document}
# <kml xmlns="http://www.opengis.net/kml/2.2" xmlns:gx="http://www.google.com/kml/ext/2.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

# WRITE / READ XML
write_xml(new_doc, "new_doc.xml")
doc2 <- read_xml("new_doc.xml", package = "xslt")

# RUN SECOND TRANSFORMATION
final_doc <- xml_xslt(doc2, style2)

final_doc
# {xml_document}
# <kml xmlns="http://www.opengis.net/kml/2.2" xmlns:gx="http://www.google.com/kml/ext/2.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
#  [1] <DATA>\n  <ROUTE>1</ROUTE>\n  <ROUTE0>001</ROUTE0>\n  <NAME>BRONZEVILLE/UNION STATION</NAME>\n  <WKDAY>1</WKDAY>\n  <SAT>0</SAT>\n  <SUN>0</SUN>\n  <SHAPE.LEN>34690.953676</ ...
#  [2] <DATA>\n  <ROUTE>2</ROUTE>\n  <ROUTE0>002</ROUTE0>\n  <NAME>HYDE PARK EXPRESS</NAME>\n  <WKDAY>1</WKDAY>\n  <SAT>0</SAT>\n  <SUN>0</SUN>\n  <SHAPE.LEN>110607.498776</SHAPE.L ...
#  [3] <DATA>\n  <ROUTE>3</ROUTE>\n  <ROUTE0>003</ROUTE0>\n  <NAME>KING DRIVE</NAME>\n  <WKDAY>1</WKDAY>\n  <SAT>1</SAT>\n  <SUN>1</SUN>\n  <SHAPE.LEN>88297.447622</SHAPE.LEN>\n</D ...
#  [4] <DATA>\n  <ROUTE>4</ROUTE>\n  <ROUTE0>004</ROUTE0>\n  <NAME>COTTAGE GROVE</NAME>\n  <WKDAY>1</WKDAY>\n  <SAT>1</SAT>\n  <SUN>1</SUN>\n  <SHAPE.LEN>106219.449701</SHAPE.LEN>\ ...
#  [5] <DATA>\n  <ROUTE>5</ROUTE>\n  <ROUTE0>005</ROUTE0>\n  <NAME>SOUTH SHORE NIGHT BUS</NAME>\n  <WKDAY>0</WKDAY>\n  <SAT>0</SAT>\n  <SUN>0</SUN>\n  <SHAPE.LEN>67048.136707</SHAP ...
#  [6] <DATA>\n  <ROUTE>6</ROUTE>\n  <ROUTE0>006</ROUTE0>\n  <NAME>JACKSON PARK EXPRESS</NAME>\n  <WKDAY>1</WKDAY>\n  <SAT>1</SAT>\n  <SUN>1</SUN>\n  <SHAPE.LEN>99573.511134</SHAPE ...
#  [7] <DATA>\n  <ROUTE>7</ROUTE>\n  <ROUTE0>007</ROUTE0>\n  <NAME>HARRISON</NAME>\n  <WKDAY>1</WKDAY>\n  <SAT>0</SAT>\n  <SUN>0</SUN>\n  <SHAPE.LEN>67830.691765</SHAPE.LEN>\n</DATA>
#  [8] <DATA>\n  <ROUTE>8</ROUTE>\n  <ROUTE0>008</ROUTE0>\n  <NAME>HALSTED</NAME>\n  <WKDAY>1</WKDAY>\n  <SAT>1</SAT>\n  <SUN>1</SUN>\n  <SHAPE.LEN>77133.131835</SHAPE.LEN>\n</DATA>
#  [9] <DATA>\n  <ROUTE>8A</ROUTE>\n  <ROUTE0>008A</ROUTE0>\n  <NAME>SOUTH HALSTED</NAME>\n  <WKDAY>1</WKDAY>\n  <SAT>1</SAT>\n  <SUN>1</SUN>\n  <SHAPE.LEN>66546.30805</SHAPE.LEN>\ ...
# [10] <DATA>\n  <ROUTE>9</ROUTE>\n  <ROUTE0>009</ROUTE0>\n  <NAME>ASHLAND</NAME>\n  <WKDAY>1</WKDAY>\n  <SAT>1</SAT>\n  <SUN>1</SUN>\n  <SHAPE.LEN>100141.31991</SHAPE.LEN>\n</DATA>
# [11] <DATA>\n  <ROUTE>X9</ROUTE>\n  <ROUTE0>009X</ROUTE0>\n  <NAME>ASHLAND EXPRESS</NAME>\n  <WKDAY>1</WKDAY>\n  <SAT>0</SAT>\n  <SUN>0</SUN>\n  <SHAPE.LEN>96064.210775</SHAPE.LE ...
# [12] <DATA>\n  <ROUTE>10</ROUTE>\n  <ROUTE0>010</ROUTE0>\n  <NAME>MUSEUM OF SCIENCE &amp; INDUSTRY</NAME>\n  <WKDAY>0</WKDAY>\n  <SAT>1</SAT>\n  <SUN>1</SUN>\n  <SHAPE.LEN>79579. ...
# [13] <DATA>\n  <ROUTE>11</ROUTE>\n  <ROUTE0>011</ROUTE0>\n  <NAME>LINCOLN</NAME>\n  <WKDAY>1</WKDAY>\n  <SAT>1</SAT>\n  <SUN>1</SUN>\n  <SHAPE.LEN>24694.573889</SHAPE.LEN>\n</DATA>
# [14] <DATA>\n  <ROUTE>12</ROUTE>\n  <ROUTE0>012</ROUTE0>\n  <NAME>ROOSEVELT</NAME>\n  <WKDAY>1</WKDAY>\n  <SAT>1</SAT>\n  <SUN>1</SUN>\n  <SHAPE.LEN>62586.111408</SHAPE.LEN>\n</D ...
# [15] <DATA>\n  <ROUTE>15</ROUTE>\n  <ROUTE0>015</ROUTE0>\n  <NAME>JEFFERY LOCAL</NAME>\n  <WKDAY>1</WKDAY>\n  <SAT>1</SAT>\n  <SUN>1</SUN>\n  <SHAPE.LEN>63343.258492</SHAPE.LEN>\ ...
# [16] <DATA>\n  <ROUTE>18</ROUTE>\n  <ROUTE0>018</ROUTE0>\n  <NAME>16TH/18TH</NAME>\n  <WKDAY>1</WKDAY>\n  <SAT>1</SAT>\n  <SUN>1</SUN>\n  <SHAPE.LEN>48076.975753</SHAPE.LEN>\n</D ...
# [17] <DATA>\n  <ROUTE>19</ROUTE>\n  <ROUTE0>019</ROUTE0>\n  <NAME>UNITED CENTER EXPRESS</NAME>\n  <WKDAY>0</WKDAY>\n  <SAT>0</SAT>\n  <SUN>0</SUN>\n  <SHAPE.LEN>32037.427404</SHA ...
# [18] <DATA>\n  <ROUTE>20</ROUTE>\n  <ROUTE0>020</ROUTE0>\n  <NAME>MADISON</NAME>\n  <WKDAY>1</WKDAY>\n  <SAT>1</SAT>\n  <SUN>1</SUN>\n  <SHAPE.LEN>54335.296018</SHAPE.LEN>\n</DATA>
# [19] <DATA>\n  <ROUTE>21</ROUTE>\n  <ROUTE0>021</ROUTE0>\n  <NAME>CERMAK</NAME>\n  <WKDAY>1</WKDAY>\n  <SAT>1</SAT>\n  <SUN>1</SUN>\n  <SHAPE.LEN>85014.706492</SHAPE.LEN>\n</DATA>
# [20] <DATA>\n  <ROUTE>22</ROUTE>\n  <ROUTE0>022</ROUTE0>\n  <NAME>CLARK</NAME>\n  <WKDAY>1</WKDAY>\n  <SAT>1</SAT>\n  <SUN>1</SUN>\n  <SHAPE.LEN>73447.885542</SHAPE.LEN>\n</DATA>
# ...

Sources

KML

Chicago Transit Authority: CTA - Bus Routes KML

XSLT 1

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                              xmlns:k="http://www.opengis.net/kml/2.2">
    <xsl:output method="xml" omit-xml-declaration="no" indent="yes"/>
    <xsl:strip-space elements="*"/>

    <xsl:template match="/k:kml">
     <xsl:copy>
       <xsl:apply-templates select="descendant::k:description"/>
     </xsl:copy>
    </xsl:template>

    <xsl:template match="k:description">
     <xsl:copy>
       <xsl:value-of select="substring-before(substring-after(., '&lt;/head&gt;'), '&lt;/html&gt;')" disable-output-escaping="yes"/>
     </xsl:copy>
    </xsl:template>

</xsl:stylesheet>

XSLT 2

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                              xmlns:k="http://www.opengis.net/kml/2.2">
    <xsl:output method="xml" omit-xml-declaration="no" indent="yes"/>
    <xsl:strip-space elements="*"/>

    <xsl:template match="/k:kml">
     <xsl:copy>
       <xsl:apply-templates select="k:description">
         <xsl:sort select="descendant::k:td[text()='ROUTE0']/following-sibling::k:td"/>
       </xsl:apply-templates>
     </xsl:copy>
    </xsl:template>

    <xsl:template match="k:description">
       <xsl:apply-templates select="descendant::k:table[2]"/>
    </xsl:template>

    <xsl:template match="k:table">
     <xsl:element name="DATA" namespace="http://www.opengis.net/kml/2.2">
       <xsl:apply-templates select="k:tr"/>
     </xsl:element>
    </xsl:template>

    <xsl:template match="k:tr">
      <xsl:element name="{k:td[1]}" namespace="http://www.opengis.net/kml/2.2">
        <xsl:value-of select="k:td[2]"/>
      </xsl:element>
    </xsl:template>

</xsl:stylesheet>

Session

> sessionInfo()

R version 4.2.1 (2022-06-23)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 22.04.3 LTS

Matrix products: default
BLAS:   /usr/lib/x86_64-linux-gnu/blas/libblas.so.3.10.0
LAPACK: /usr/lib/x86_64-linux-gnu/lapack/liblapack.so.3.10.0

locale:
 [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C               LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8     LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8   
 [7] LC_PAPER=en_US.UTF-8       LC_NAME=C                  LC_ADDRESS=C               LC_TELEPHONE=C             LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C       

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] xslt_1.4.4 xml2_1.3.6

loaded via a namespace (and not attached):
 [1] compiler_4.2.1  fastmap_1.1.0   cli_3.4.1       htmltools_0.5.3 tools_4.2.1     rstudioapi_0.13 yaml_2.3.6      Rcpp_1.0.9      rmarkdown_2.14  knitr_1.39      xfun_0.31      
[12] digest_0.6.30   rlang_1.1.2     evaluate_0.15 

Error installing xslt on GitHub Actions

Not entirely sure if this is an xslt error, or just something weird on GitHub Actions

##[error]Error: package or namespace load failed for ‘xslt’ in dyn.load(file, DLLpath = DLLpath, ...):
ERROR: loading failed
* removing ‘/Users/runner/runners/2.168.0/work/_temp/Library/xslt’
 unable to load shared object '/Users/runner/runners/2.168.0/work/_temp/Library/00LOCK-xslt/00new/xslt/libs/xslt.so':
  dlopen(/Users/runner/runners/2.168.0/work/_temp/Library/00LOCK-xslt/00new/xslt/libs/xslt.so, 6): Symbol not found: _exsltRegisterAll
  Referenced from: /Users/runner/runners/2.168.0/work/_temp/Library/00LOCK-xslt/00new/xslt/libs/xslt.so
  Expected in: flat namespace
 in /Users/runner/runners/2.168.0/work/_temp/Library/00LOCK-xslt/00new/xslt/libs/xslt.so
##[error]Error: loading failed

https://github.com/r-lib/xml2/runs/571881855?check_suite_focus=true#step:5:74

The workflow basically was just calling install.packages("xslt") and that does work without issue locally, so I am not clear what is different on the GHA runner. Though now that I look at the log it seems like the PKG_LIBS are not being added appropriately for some reason

Using PKG_LIBS=

https://github.com/r-lib/xml2/runs/571881855?check_suite_focus=true#step:5:55

calling xml_xslt causes R to close

Dear Jeroen and the ropensci team,

Much thanks for developing the xslt library, and it installs well in R 3.4.0 and the example works as expected. However when I try and use one of my own version 1.0 xslt file (which processes correctly in Saxon) with xml_xslt it causes my R session to close.

Apologies if I am doing something wrong, but just wondered if there was anything in my xslt (shown below) which would cause xslt to close my r session?

Much thanks again,

Paul Morris,
National Science Foundation

<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    version="1.0">

  <xsl:strip-space elements="*" />

  <xsl:output encoding="UTF-8" method="text" />

  <xsl:key name="labelById" match="labels/list/label" use="@id" />

  <xsl:template match="/">Label,Proposal_ID,Submission_Date
<xsl:apply-templates select="result/documents/list" />
  </xsl:template>

  <xsl:template match="documents/list/document">"<xsl:apply-templates select="labels" />",<xsl:value-of select="content/field[@name='Division']" />,<xsl:value-of select="content/field[@name='Proposal_Title']" /><xsl:text>
</xsl:text>
  </xsl:template>

</xsl:stylesheet>

Please add to documentation: params in xml_xslt must be coerced to type character

In trying to add parameters to xml_xslt, I learned that the params list must be coerced to type character.

To supply a value for the parameter 'viafrversion' in the xslt stylesheet,

<xsl:param name="version" />

the following R code generates an error:

v <-list(version=utils::packageVersion(pkg))
result <- xslt::xml_xslt(xml, xslt,  params =v )

The following code works:

v <-list(version=as.character(utils::packageVersion(pkg)))
result <- xslt::xml_xslt(xml, xslt,  params =v )

feature request: support for <xsl:param/>

Hi Jeroen

It would be great if one could pass parameter values from 'xml_xslt' to the XSL stylesheet where those values are used instead of the default values specified in the corresponding xsl:param/ elements. (In 'xsltproc', this is available via the --stringparam option.)

Cheers
/thomas

BTW: Great work!

R studio crashes when there is a syntax error in xsl file

Hello!
Thank you for this package. It is very useful but I find it difficult to work with as it causes R studio to crash.

Steps to reproduce:

  1. have a file with XML data to be transformed as a valid XML document
  2. have a file with an XSL stylesheet as a valid XML document but with errors in XSL calls. Some examples:
  • <xsl:call-template name='{$name}'/> (invalid QName)
  • xsl:if</xsl:if> (test attribute missing)
  1. Apply transformation to the data with xslt::xml_xslt(data file,xslt file).

The relevant error message will be displayed (like those provided in brackets in examples) but a few seconds later the R studio will crash.
image

PS If the XSL file is an invalid XML then when opening the file with xml2::read_xml(filename):

  • the error message will be displayed
  • the xml2 package will lock the file (the file can't be modified anymore)
  • xml2 call seems to keep running in the background despite aborting the process
  • ultimately after a few minutes/more calls like this the R studio will crash as well unless you manually reset the R session before.

R Studio version: 4.1.0
xml2 version: 1.3.3
xslt version: 1.4.3
(all installed packages are updated to the most recent version)

Sys.info():

  • sysname: "Windows"
  • release: "10 x64"
  • version: "build 19044"
  • machine: "x86-64"

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.