An InPlace CMS template is an usual XSLT transformation. There is a lot of resources, both online and offline, to learn XSLT. This page highlights a few patterns.

Identity transformation

The identity template is the starting point for all other templates.

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<!-- -->
<xsl:output encoding="ascii" omit-xml-declaration="yes" method="html"/>

<xsl:template match="node()|@*">
  <xsl:copy>
    <xsl:apply-templates select="node()|@*"/>
  </xsl:copy>
</xsl:template>

</xsl:stylesheet>

The element xsl:stylesheet and its attributes are the required skeleton of an XSLT stylesheet. The second element, xsl:output, specifies how to serialize the result of transformation.

The only xsl:template matches nodes of a document. A matched node and its attributes are copied to the output tree as is, and template processing is continued for the children.

This XSLT transformation is called “identity template”, as the output document is the same as the input document.

Literal output

To update the div, which has the attribute id set to footer:

<xsl:template match="div[@id='footer']">
  <div id="footer">
    <hr />
    ... more footer goes here ...
  </div>
</xsl:template>

Parametric output

To update the div, which has the attribute id set to header, retaining the content of h1:

<xsl:template match="div[@id='header']">
  <div id="header">
    ... your header ...
    <xsl:copy-of select=".//h1"/>
    ... your header continues ...
  </div>
</xsl:template>

Structure enchancement

If the stylesheet link is missed, add it.

<xsl:template match="head[not(link[@rel='stylesheet'])]">
  <xsl:copy>
    <xsl:copy-of select="node()"/>
    <link rel="stylesheet" href="inplace.css" type="text/css"/>
    <xsl:text>&#xa;</xsl:text>
  </xsl:copy>
</xsl:template>

Comments to tags

It's possible to have implicit markup. Consider the HTML fragment:

lalala1
<!--InPlaceCMS:xxx-->
lalala2
<!--/InPlaceCMS-->
lalala3

On load, this is automatically transformed to such XML:

lalala1
<InPlaceCMS name="xxx">
lalala2
</InPlaceCMS>
lalala3

On serialization, the reverse transformation occurs.