Documentation Center

Best Practices- HTML

A description of the concepts to consider for HTML in this XML editor.

Content Editor needs valid XHTML in its output. The following considerations for HTML in Content Editor can help you achieve this goal.

  • Provide HTML elements for editable content. Each XML node needs to have an HTML element in the template in order to be editable.
  • Special characters need to be saved as they are, not as entities.
  • Content Editor needs valid XHTML output.
  • Don't use <legend> or <fieldset>

Provide HTML elements for editable content

You will have a problem if, for example, when a <xsl:template> in your XSL Stylesheet does not output an element but just copies text content to the output HTML. Content Editor will be unable to find the source content and the generated text will not be editable. For this reason, the general rule of thumb is that each template should generate an HTML element:
<xsl:template match="*">
<div class="generic-element">
<xsl:apply-templates />
</div>
</xsl:template>

Entities and special characters

Entities, special characters and such, are best added in UTF-8 encoding. Of course it impedes the searchability of the documents if you save them as HTML entities. For transport however it isn't an issue to save special characters as entities.

Valid XHTML

Content Editor needs to have valid XHTML.

This means that you cannot put block elements such as <table>, <div> or a <li> element inside a paragraph. The problem here is that you are trying to put block elements inside an element, the paragraph that has an optional closing tag. Consider if you tried to wrap a div in a p element as follows

<p><div></div></p>
Internet Explorer will assume a </p> closing tag before drawing the <div> : (e.g.: <p></p><div></div>) because you cannot have a block level element inside the paragraph. This means that your paragraph isn't wrapping the <div> is rendered after the paragraph. The HTML will look like this:
<p></p>
<div>your text from the xml</div>
</p>

Don't use <legend> or <fieldset>

Well, that says it all really. Don't use those elements in your XSL output for Content Editor HTML.