Principal XSLT module

The XSLT module that is called directly by Berlioz is the principal module. It is defined by your Berlioz configuration.

Usage

Usually, the principal XSLT module simply defines the output type using <xsl:output> and references other XSLT modules using <xsl:import> or <xsl:include>.

It should be kept as simple as possible.

Standard mapping

When using the standard mapping and standard file layout (e.g. with Kickstart), there is a principal module per group of services per output type.

Standard mapping
MatchesMedia typePrincipal XSLT module
*.htmltext/html/WEB-INF/xslt/html/[group].xsl
*.jsonapplication/json/WEB-INF/xslt/json/[group].xsl
*.xmlapplication/xml/WEB-INF/xslt/xml/[group].xsl

Examples

Below are some examples taken from Berlioz base.

HTML principal module

This module assembles all the modules needed for an HTML output and defines the overall structure for a web page.

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0"
                xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                xmlns:xs="http://www.w3.org/2001/XMLSchema"
                exclude-result-prefixes="#all">

<!-- Import library modules first -->
<xsl:import href="lib/psml-beta7-3.xsl"/>

<!-- Import common modules second -->
<xsl:import href="common/app.xsl"/>
<xsl:import href="common/topbar.xsl"/>
<xsl:import href="common/header.xsl"/>
<xsl:import href="common/footer.xsl"/>
<xsl:import href="common/psml.xsl"/>

<!-- Import modules specific to each service last -->
<xsl:import href="default/home.xsl"/>
<xsl:import href="default/specimen.xsl"/>

<!-- General Output properties. -->
<xsl:output method="html" encoding="utf-8" indent="yes" undeclare-prefixes="no" media-type="text/html"/>

<!--
  Main HTML structure of every page.

  Each part is using a separate template mode.
  The actual templates for each mode are defined elsewhere to keep this module 
  clean and simple.
-->
<xsl:template match="/">
<!-- Display the HTML5 Doctype -->
<xsl:text disable-output-escaping="yes"><![CDATA[<!doctype html>
]] ></xsl:text>
<html>
  <head>
    <xsl:apply-templates mode="head"/>
  </head>
  <body>
    <xsl:apply-templates mode="topbar"/>
    <xsl:apply-templates mode="header"/>
    <xsl:apply-templates mode="main"/>
    <xsl:apply-templates mode="footer"/>
    <xsl:apply-templates mode="bottom"/>
  </body>
</html>
</xsl:template>

</xsl:stylesheet>

XML principal module

This module returns the same as the source XML.

<?xml version="1.0" encoding="UTF-8"?>
<xsl:transform version="2.0"
                xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                xmlns:xs="http://www.w3.org/2001/XMLSchema"
                exclude-result-prefixes="#all">

<!-- XML properties -->
<xsl:output method="xml" media-type="application/xml" indent="no" encoding="utf-8" />

<!-- Default -->
<xsl:template match="/root">
<xsl:sequence select="."/>
</xsl:template>

</xsl:transform>

JSON principal module

The XML generated by this template should map to a simple JSON tree model following the Aeson format.

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0"
                xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                xmlns:xs="http://www.w3.org/2001/XMLSchema"
                xmlns:json="http://pageseeder.org/JSON"
                exclude-result-prefixes="#all">

<!-- JSON output properties -->
<xsl:output method="xml" media-type="application/json" encoding="utf-8"/>

<!-- Default -->
<xsl:template match="/root">
<json:object/>
</xsl:template>

<!-- Match service 'home' -->
<xsl:template match="/root[@service='home']">
  <!-- Return an object with property 'greeting' -->
  <json:object greeting="{//greeting}" />
</xsl:template>

</xsl:stylesheet>

Created on , last edited on