 <p>See scala.xml.transform._ and the corresponding Stack Overflow questions.</p> <p>It will probably look somewhat like this:</p> <p><a href="http://www.scalakata.com/5022b395e4b032f990af0493" rel="nofollow"></p> <pre><code>import scala.xml._ import transform._ case class Article( title: String, content: String ) val articleList = List( Article("title 1","content 1"), Article("title 2","content 2") ) class TransformArticle(title: String, content: String) extends RewriteRule { override def transform(n: Node): Seq[Node] = n match { case div @ &lt;div/&gt; =&gt; div match { case elem: Elem if elem \ "@class" contains Text("title") =&gt; elem copy (child = Text(title)) case elem: Elem if elem \ "@class" contains Text("content") =&gt; elem copy (child = Text(content)) case other =&gt; other } case other =&gt; other } } val article_template = &lt;div&gt; &lt;div class="title"&gt;&lt;/div&gt; &lt;div class="content"&gt;&lt;/div&gt; &lt;!-- some other markups don't know --&gt; &lt;/div&gt; Group( articleList.flatMap( article =&gt; { new RuleTransformer(new TransformArticle(article.title, article.content)) transform article_template }) ) </code></pre> <p></a></p>