API
Documentation for XSLT.
XSLT.XMLErrorXSLT.XptrXSLT.xsltPtrXSLT.doc_xslt_applyXSLT.get_xXSLT.keep_string_quotedXSLT.parse_parametersXSLT.read_stylesheetXSLT.read_xmlXSLT.xmlFreeDocXSLT.xmlParseFileXSLT.xmlReadFileXSLT.xml_xsltXSLT.xsltApplyStylesheetXSLT.xsltFreeStylesheetXSLT.xsltParseStylesheetFileXSLT.xsltSaveResultToString
XSLT.XMLError — TypeAn error detected by libxml2.
XSLT.Xptr — TypeXptrA pointer to an xsltPtr. This is a trick to make a xsltStylesheetPtr and xmlDocPtr pointers.
XSLT.xsltPtr — TypexsltPtrA 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.
XSLT.doc_xslt_apply — Methoddoc_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.jlDocumentor a LightXML.jlXMLDocument.xslt: can be a file path or anxsltPtr(output ofread_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)XSLT.get_x — Methodget_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.
XSLT.keep_string_quoted — Methodkeep_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.
XSLT.parse_parameters — Methodparse_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".
XSLT.read_stylesheet — Methodread_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)XSLT.read_xml — Methodread_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)XSLT.xmlFreeDoc — MethodxmlFreeDoc(res::Xptr)Free the memory allocated to the document res.
XSLT.xmlParseFile — MethodxmlParseFile(filename::String)Parse an XML file into a document.
XSLT.xmlReadFile — MethodxmlReadFile(filename::String; encoding="UTF-8", options=0)Read an XML file into a document.
XSLT.xml_xslt — Functionxml_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 byread_xml, an EzXML.jlDocument
or a LightXML.jl XMLDocument.
xslt: can be a file path or anxsltPtr(output ofread_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)XSLT.xsltApplyStylesheet — MethodxsltApplyStylesheet(xslt::Xptr, doc::Xptr, params<:AbstractString)Apply the stylesheet xslt to the document doc with the given params.
XSLT.xsltFreeStylesheet — MethodxsltFreeStylesheet(cur::Xptr)Free the memory allocated to the stylesheet cur.
XSLT.xsltParseStylesheetFile — MethodxsltParseStylesheetFile(filename::String)Parse an XSLT file into a stylesheet.
XSLT.xsltSaveResultToString — MethodxsltSaveResultToString(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.