xmerl_xs(3erl)
okay so bestie, welcome to xmerl_xs(3erl) β officially an Erlang Module Definition β and yes, this is where Erlang and XSLT are lowkey giving the same functional-programming energy π
β¨
πΈ NAME πΈ
xmerl_xs β Erlang has similarities to XSLT since both languages have a functional programming approach. That's the whole name blurb, and honestly? Iconic. π¦
π DESCRIPTION π
Erlang has similarities to XSLT since both languages have a functional programming approach. Using xmerl_xpath it is possible to write XSLT like transforms in Erlang. fr fr, that's the opening vibe.
XSLT stylesheets are often used when transforming XML documents, to other XML documents or (X)HTML for presentation. XSLT contains quite many functions and learning them all may take some effort. This document assumes a basic level of understanding of XSLT. No cap β bring your baseline XSLT knowledge and we're good.
Since XSLT is based on a functional programming approach with pattern matching and recursion it is possible to write similar style sheets in Erlang. At least for basic transforms. This document describes how to use the XPath implementation together with Erlangs pattern matching and a couple of functions to write XSLT like transforms. That's the main character energy of this module: XPath + Erlang pattern matching + a couple of functions = XSLT-ish transforms, periodt.
This approach is probably easier for an Erlanger but if you need to use real XSLT stylesheets in order to "comply to the standard" there is an adapter available to the Sablotron XSLT package which is written i C++. See also the Tutorial. π
π₯ EXPORTS π₯
Here's the exports menu, bestie β every signature stays exactly as it is, no cap.
π§© built_in_rules(Fun, E) -> List
The default fallback behaviour. Template funs should end with:
template(E) -> built_in_rules(fun template/1, E).
Literally the fallback bestie β your template fun wraps up with that line. π
π select(String::string(), E) -> E
Extracts the nodes from the xml tree according to XPath.
See also: value_of/1.
π¬ value_of(E) -> List
Types:
E = term()
Concatenates all text nodes within the tree.
Example:
<xsl:template match="title">
<div align="center">
<h1><xsl:value-of select="." /></h1>
</div>
</xsl:template>
becomes:
template(E = #xmlElement{name='title'}) ->
["<div align="center"><h1>",
value_of(select(".", E)), "</h1></div>"]
So the XSLT above turns into this Erlang template. Slay. π
π«Ά xslapply(Fun::Function, EList::list()) -> List
Types:
Function = () -> list()
xslapply is a wrapper to make things look similar to xsl:apply-templates.
Example, original XSLT:
<xsl:template match="doc/title">
<h1>
<xsl:apply-templates/>
</h1>
</xsl:template>
becomes in Erlang:
template(E = #xmlElement{ parents=[{'doc',_}|_], name='title'}) ->
["<h1>",
xslapply(fun template/1, E),
"</h1>"];
π AUTHORS π
The authors entry is literally <> β mysterious, iconic, no cap. π
Sign-off from the footer: source/version is xmerl 1.3.31.1, page is xmerl_xs(3erl) β and since the original footer has no date, we're not inventing one, bestie πβ¨
π¦ where this page comes from
- ubuntu noble: erlang-manpages 1:25.3.2.8+dfsg-1ubuntu4 Β· Apache-2.0
- ubuntu noble: erlang-manpages 1:25.3.2.8+dfsg-1ubuntu4.8 Β· Apache-2.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms