Archive

Using XSLT with bad HTML

Posted on Tue 19 Oct, 2004

We have a PHP CMS with a lot of poorly written HTML in the client-contributed content. This kept causing my XSL template system to output XML errors. I got around this problem by:

  1. wrapping content in CDATA tags
  2. Checking if the content is valid XML with xml_parse() in PHP, if not I add a CDATA tag and try again.
  3. Strip out bad characters that may have crept in from Word
  4. Process the XSL and XML using xsl:value-of tags with disable-output-escaping=”yes”

Using CDATA tags around unpredictable HTML helps prevent problems with the XML parser. Without the final step, the resulting HTML

Continue reading → | Tagsphp, xslt, programming

Processing Textile text with XSLT

Posted on Thu 7 Oct, 2004

Textile provides a simple way of writing human-friendly text that can easily be translated to XHTML. HTML tags are simplified into a set of phrase and block modifiers; even tables and attributes can be created.

I was looking at the PHP code for this and wondering if I could create an XSL file that could translate similar text into XHTML. I created some XML to contain my text:

And then used the following recursive algorithm to process it in XSLT:

...
Continue reading → | Tagsxslt, programming, snippets, tips, textile