Using XSLT in Xopus
Using XSLT the right way can speed up your Xopus experience, and make sure that you can find what you were looking for.
-
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
Xopus uses the XSLT engine from the browser Xopus runs in. As a result, XSLT 2.0 is not supported in Xopus at this moment.
Output a root element
Xopus 3 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; Xopus 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 disable-ouput-escaping
It is advisable not to 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.), and next to that Xopus cannot resolve the nodes that are processed in such a way, and therefore cannot make them editable.
- Documentation
- › Best Practices
- › Using XSLT in Xopus