Search

Hi,

I have an unknown number of nodes (paragraphs). I would like to combine the contents from all these nodes, and whatever content there is outside the nodes, into one single, new node.

For example:

<div>
<p>this</p>
particular content
<p><a href="">needs to</a></p>
<p>be combined</p>
</div>

I would like to transform this to

<blockquote>
this particular content <a href="">needs to</a> be combined
</blockquote>

Since I don't know the exact structure of my source, this proves more difficult than I anticipated. I'm thinking there must be a simple solution. Any help is welcome!

yes there's a simple solution if (only if) you have a coherent structure.

You can use a ninja technique. Use the standard HTML ninja technique packaged with symphony to manage HTML, then add the following templates to it. (I'd suggest you change the mode from html as you might already be using this elsewhere.

<xsl:template match='div' mode='html>
    <blockquote>
        <xsl:apply-templates select='*' mode='html>
    </blockquote>
</xsl:template>

<xsl:template match='p' mode='html>
    <xsl:apply-templates select='*|text' mode='html>
</xsl:template>

your additional templates should look like above; obviously then do a call template mode='html' on the whole block you want.

Create an account or sign in to comment.

Symphony • Open Source XSLT CMS

Server Requirements

  • PHP 5.3-5.6 or 7.0-7.3
  • PHP's LibXML module, with the XSLT extension enabled (--with-xsl)
  • MySQL 5.5 or above
  • An Apache or Litespeed webserver
  • Apache's mod_rewrite module or equivalent

Compatible Hosts

Sign in

Login details