API

Documentation for XSLT.

XSLT.XptrType
Xptr

A pointer to an xsltPtr. This is a trick to make a xsltStylesheetPtr and xmlDocPtr pointers.

source
XSLT.xsltPtrType
xsltPtr

A buffer structure used for temporary storage. The idea is to map this struct to other structs in libxslt.

I stole this from LightXML.jl. See their implementations of the xmlBuffer here.

source
XSLT.doc_xslt_applyMethod
doc_xslt_apply(doc, xslt, params)

Apply the stylesheet xslt to the XML doc with the given params.

Arguments

  • doc: can be a file path or an EzXML.jl Document or a LightXML.jl XMLDocument.
  • xslt: can be a file path or an xsltPtr (output of read_stylesheet).
  • params: a vector of strings with key-values for parameters, e.g. ["param_name=param_value", "param_name2=param_value2"].

Example

using EzXML

# Get the path to the test files in the package:
test_dir = joinpath(dirname(pathof(XSLT)), "..", "test", "files")

xml = readxml(joinpath(test_dir, "cd_catalog.xml"))
xslt = joinpath(test_dir, "cd_catalog.xsl")

res = doc_xslt_apply(xml, xslt)

write("cd_catalog.html", res)
source
XSLT.get_xMethod
get_x(x)

Return x if it is a file path or a pointer (Ptr), or get the pointer to the xmlDocPtr from x if x is an EzXML.jl Document or a LightXML.jl XMLDocument.

source
XSLT.keep_string_quotedMethod
keep_string_quoted(s)

If s is a string, return a string with quotes around it. Otherwise, return string(s). It is used to keep the quotes around the parameters in the xml_xslt function.

source
XSLT.parse_parametersMethod
parse_parameters(params)

Convert the parameters to a vector of strings. The parameters can be a vector of strings, a named tuple, a dictionary, or nothing. If the parameters are a vector of strings, they are returned as is. If the parameters are a named tuple or a dictionary, they are converted to a vector of strings. If the parameters are nothing, an empty vector of strings is returned.

The vector of strings is used as input parameters to xsltApplyStylesheet, which expects a null-terminated array of strings. The strings are of the form key value. The key is the name of the parameter and the value is the value of the parameter. The value can be a string, a number, or a boolean. If the value is a string, it must be quoted, i.e. key "value".

source
XSLT.read_stylesheetMethod
read_stylesheet(filename::String)

Read the stylesheet filename and return a xsltPtr (equivalent to xsltStylesheetPtr). The stylesheet can then be applied to an XML document using xml_xslt.

Example

using XSLT

# Get the stylesheet from the test files in the package:
file = joinpath(dirname(pathof(XSLT)), "..", "test", "files", "cd_catalog.xsl")

# Read the stylesheet:
xslt = read_stylesheet(file)
source
XSLT.read_xmlMethod
read_xml(file)

Read the XML file file and return a xsltPtr (equivalent to xmlDocPtr).

The function does not parse the XML file, it just reads it and put it in a pointer for further usage in the XSLT package. If you want to parse the XML file, use the functions from EzXML.jl or LightXML.jl.

Example

using XSLT

# Get the XML file from the test files in the package:
file = joinpath(dirname(pathof(XSLT)), "..", "test", "files", "cd_catalog.xml")

# Read the XML file:
xml = read_xml(file)
source
XSLT.xmlReadFileMethod
xmlReadFile(filename::String; encoding="UTF-8", options=0)

Read an XML file into a document.

source
XSLT.xml_xsltFunction
xml_xslt(x, xslt, params= nothing)

Apply the stylesheet xslt to the XML x with the given params.

Arguments

  • x: can be a file path, a pointer returned by read_xml, an EzXML.jl Document

or a LightXML.jl XMLDocument.

  • xslt: can be a file path or an xsltPtr (output of read_stylesheet).
  • params: a dictionnary, tuple or Vector{Pair} of key-values for parameters. Can also be

directy a vector of strings of the form ["param1", ""stringvalue1"", "param2", "1"].

Returns the result as a string.

Example

using EzXML
using XSLT

# Get the path to the test files in the package:
test_dir = joinpath(dirname(pathof(XSLT)), "..", "test", "files")

xml = readxml(joinpath(test_dir, "cd_catalog.xml"))
xslt = joinpath(test_dir, "cd_catalog.xsl")

res = xml_xslt(xml, xslt)

write("cd_catalog.html", res)
source
XSLT.xsltApplyStylesheetMethod
xsltApplyStylesheet(xslt::Xptr, doc::Xptr, params<:AbstractString)

Apply the stylesheet xslt to the document doc with the given params.

source
XSLT.xsltSaveResultToStringMethod
xsltSaveResultToString(xml::Xptr, xslt::Xptr)

Return the transformed XML file (xml) to a string considering an xslt transformation. The xslt is given so that output-related information contained in the stylesheet, such as the encoding to be used, is used in output.

See doc and tutorial here: https://gnome.pages.gitlab.gnome.org/libxslt/tutorial2/libxslt_pipes.html

Returns a tuple of two: the output string and its length.

source