Documentation Center

Best practices- XSLT

Using XSLT the right way can speed up your editor experience and make sure that you an find elements easily.

  • XSLT 1-only
  • Output a root element
  • Empty nodes need to have a representation in HTML
  • Do not use disable-output-escaping.

XSLT 1-only

Content Editor uses the XSLT engine from the browser it runs in. As a result, XSLT 2.0 is not supported in Content Editor at this moment.

Output a root element

Content Editor needs a (single) root element in the XSLT output, otherwise it doesn't work. A quick solution is to insert a <div> for the XML root node:

<xsl:template match="/">
  <div>
    <xsl:apply-templates/>
  </div>
</xsl:template>

Empty nodes

If you have an empty node in your XML, and parse this node in your XSLT in a template which does not output any HTML, then Xopus cannot draw anything in the HTML output, with which you can find that node.

For example this XML:
<document>
  <header1/>
  ...
when processed by the following stylesheet
<xsl:template match="document">
    <h1>
      <xsl:apply-templates select="header1"/>
    </h1>
  </xsl:template>

  <xsl:template match="header1">
    <xsl:value-of select="."/>
  </xsl:template>
...will produce nothing; Content Editor cannot generate an empty text-node anywhere, because there is no place for it. Therefore templates that output a node, should output at least some HTML if the node is empty. The tags for the header should be in the template.
<xsl:template match="header1">
    <h1>
      <xsl:value-of select="."/>
    </h1>
  </xsl:template>

Do not use the disable-output-escaping attribute

Do not use disable-output-escaping, since it can be used to create invalid output (nodes that aren't closed, or closed at the wrong position, etc.). As well, Content Editor cannot resolve nodes that are processed in such a way, and therefore cannot make them editable.