LKBEN10995: Howto keep html in an xml document even after a transform with xslproc


This article has not been checked!

LKB | Created: 02/04/2020 | Version: 0 | Language: EN | Rating: 0 | Outdated: False | Marked for deletion: False

Author: Wim Peeters - Keskon GmbH & Co. KG


Symptom

You have an xml document with partly html content

Cause

This can be tricky. A better way is to not implement html in xml.

Solution

To keep the html part for a certain entry in an xml file, you need to write a special xsl file. In the xsl file you can define the way the contents is converted into html. In this case, you should ommit another conversion on the html.

The following is the contents of an xsl file in which a certain entry, in this case "solution", is already html.

<?xml version="1.0" encoding="ISO-8859-1"?>

<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:template match="/">

 <html>
  <body>
    <h1>Lubby Knowledgebase Article</h1>
    <h2>Title</h2>

    <p>
        <xsl:value-of select="lkb/title"/>
    </p>

    <h2>Symptom</h2>

    <p>
        <xsl:value-of select="lkb/symptom"/>
    </p>

    <h2>Cause</h2>

    <p>
        <xsl:value-of select="lkb/cause"/>
    </p>

    <h2>Solution</h2>

    <p>
        <xsl:value-of select="lkb/solution" disable-output-escaping="yes"/>
    </p>

  </body>
 </html>
</xsl:template>
</xsl:stylesheet> 

About the Author

Wim Peeters is electronics engineer with an additional master in IT and over 30 years of experience including time spent in support, development, consulting, training and database administration. Wim has worked with SQL Server since version 6.5. He has developed in C/C++, Java and C# on Windows and Linux in different European countries and different European languages. He writes knowledge base articles to solve IT problems and publishes them on the Lubby Knowledge Platform where he is one of the most important contributors and the main developer.

Disclaimer:

The information provided in this document is intended for your information only. Lubby makes no claims to the validity of this information. Use of this information is at own risk!