XSLT like transforms in Erlang using xmerl

Mikael Karlsson <>
Thu Jan 30 11:41:35 CET 2003

looks great, I hope this is something thats targeted for your next version
of STL? I think I will need a coup of coffe or so before I dive into your
code details though :-)

Now this assumes that you have a source formatted in EHTML,
meaning you need a parser if your source is XML or that you 
already are in "Yaws space" , doesn't it ?

My reason to use xmerl is:

1. I can read (parse) an ordinary XML document.

2. the xpath implementation in xmerl combined with pattern matching in Erlang
    makes it quite easy to write "stylesheets" that look very similar to XSLT
   sheets. It is rather straighforward to grab an XSLT sheet and rewrite it as
   an Erlang sheet.
   The select(Str,E)  function below is just a call to
   xmerl_xpath:string(Str,E). Xpath is a quite substantial part of XSLT.

  <xsl:template match="title">
    <div align="center"><h1><xsl:value-of select="." /></h1></div>

  template(E = #xmlElement{name='title'}) ->
      ["<div align=\"center\"><h1>", value_of(select(".", E)), "</h1></div>"];

    <xsl:template match="doc/title">

  template(E = #xmlElement{ parents=[{'doc',_}|_], name='title'}) ->
           xslapply( fun template/1, E),

 Easy, peasy :-)

3. You can export directly to XML (and other formats), so you do not 
     need Yaws. This might happen.

My request was if this would add value to the xmerl application, I hope it 
does. If Yaws and other apps would benefit as well, so much better.


Thursday 30 Jan 2003 Vladimir Sekissov wrote:
> Good day,
> Yaws has simple and excellent idea of EHTML. Here are my two cents.
> XSLT like transforms in Erlang without xmerl.
> Example in source (exmlt:test/0) transforms
> {user, [],
>      [{first_name, [], "Tom"},
>       {last_name, [], "Jones"}
>      ]}
> to
> {form,[{action,"adduser"}],
>       [{table,[],
>               [{tr,[{class,"rowset0"}],
>                    [{td,[],"first_name"},
> {td,[],[{input,[{name,"first_name"},{value,"Tom"}]}]}]},
> {tr,[{class,"rowset1"}],
>                    [{td,[],"last_name"},
> {td,[],[{input,[{name,"last_name"},{value,"Jones"}]}]}]}|
> {tr,[{colspan,"2"}],
>                    [{td,[],[{input,[{type,"submit"},{name,"save"}]}]}]}]}]}
> Best Regards,
> Vladimir Sekissov
> ------------------------------ cut  here ---------------------------

More information about the erlang-questions mailing list