original XSLT:
|
becomes in Erlang:
|
|
becomes:
|
A complete example with the XSLT sheet in the xmerl distribution.
|
Erlang transformation of previous example:
|
It is important to end with a call to
xmerl_xs:built_in_rules/2
if you want any text to be written in "push" transforms.
That are the ones using a lot xslapply( fun
template/1, E )
instead of
value_of(select("xpath",E))
,
which is pull...
The largest example is the stylesheet to transform this document
from the Simplified Docbook XML format to xhtml. The source
file is sdocbook2xhtml.erl
.
The function for-each is quite common in XSLT stylesheets. It can often be rewritten and replaced by select/1. Since select/1 returns a list of #xmlElements and xslapply/2 traverses them it is more or less the same as to loop over all the elements.
The XSLT position() and #xmlElement.pos are not the same. One has to make an own position in Erlang.
|
Can be written as
|
In XSLT you have "root" access to the top of the tree with XPath, even though you are somewhere deep in your tree.
The xslapply/2 function only carries back the child part of the tree to the template fun. But it is quite easy to write template funs that handles both the child and top tree.
The following example piece will prepend the article title to any section title
|