title: Replace wrapping tags and reverse
body: <p>We have a legacy system that requires a format which is not html but is close enough to be confusing. On our shiny front end website we have an instance of CKEditor that allows users to edit this a-bit-like-html-but-not-really format.</p>
  
  <p>The <em>big</em> difference is that our format does not understand <code>&lt;p&gt;</code> tags. It expects new lines to be formatted with <code>&lt;br /&gt;</code> instead. CKEditor can be set to operate in <code>BR</code> mode but, perhaps unsurprisingly, this causes some annoying user interface bugs.</p>
  
  <p>As an alternative, I'm considering allowing it to run in its default <code>P</code> mode and replacing the tags on the server with some XSLT. This is easy enough in the one direction:</p>
  
  <p>Transforming:
  </p>
  
  <pre><code>&lt;root&gt;
  &lt;p&gt;Test&lt;/p&gt;&lt;p&gt;Test&lt;/p&gt;&lt;p&gt;Test&lt;/p&gt;
  &lt;p&gt;&lt;b&gt;Test&lt;/b&gt;&lt;/p&gt;
  &lt;/root&gt;
  </code></pre>
  
  <p>With:
  </p>
  
  <pre><code>&lt;xsl:template match="@*|node()"&gt;
      &lt;xsl:copy&gt;
          &lt;xsl:apply-templates select="@*|node()"/&gt;
      &lt;/xsl:copy&gt;
  &lt;/xsl:template&gt;
  &lt;!-- Replace `[p]contents[/p]` with `contents[br /]` --&gt;
  &lt;xsl:template match="p"&gt;
      &lt;xsl:apply-templates/&gt;&lt;br/&gt;
  &lt;/xsl:template&gt;
  </code></pre>
  
  <p>Results in:
  </p>
  
  <pre><code>&lt;root&gt;Test&lt;br/&gt;Test&lt;br/&gt;Test&lt;br/&gt;&lt;b&gt;Test&lt;/b&gt;&lt;br/&gt;&lt;/root&gt;
  </code></pre>
  
  <p>The question is, have I lost too much information to do the same process in reverse? And if not, what's the best way of approaching this? Is XSLT even the right option?</p>