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.
The big difference is that our format does not understand <p> tags. It expects new lines to be formatted with <br /> instead. CKEditor can be set to operate in BR mode but, perhaps unsurprisingly, this causes some annoying user interface bugs.
As an alternative, I’m considering allowing it to run in its default P mode and replacing the tags on the server with some XSLT. This is easy enough in the one direction:
Transforming:
<root>
<p>Test</p><p>Test</p><p>Test</p>
<p><b>Test</b></p>
</root>
With:
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<!-- Replace `[p]contents[/p]` with `contents[br /]` -->
<xsl:template match="p">
<xsl:apply-templates/><br/>
</xsl:template>
Results in:
<root>Test<br/>Test<br/>Test<br/><b>Test</b><br/></root>
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?
How about:
With Saxon 6.5.5 that converts
into