Author:
Nils
Version:
1.1
Release Date:
7 May 2010
Category:
Output

Description

This utility makes use of Allen’s HTML Ninja Technique and provides a simple way to change the hierarchy of headlines.

This is useful if you you don’t want authors to take care of headline levels (h1, h2, h3) when creating entries. Using this templates authors can always start this a h1 and you can adjust the output to the needed level.

XSLT

View Raw
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<!--
	XSLT NINJA
	http://www.getsymphony.com/learn/articles/view/html-ninja-technique/
-->
<xsl:template match="//*" mode="ninja">

	<!-- Adjust headline hierarchy by this number -->
	<xsl:param name="level" select="0" />
	
	<!-- Create element -->
	<xsl:element name="{name()}">
	
		<!-- Apply templates for inline elements, attributes and text nodes -->
		<xsl:apply-templates select="* | @* | text()" mode="ninja">
			<xsl:with-param name="level" select="$level" />
		</xsl:apply-templates>
		
	</xsl:element>
	
</xsl:template>

<!-- 
	Reapply attributes 
-->
<xsl:template match="//@*" mode="ninja">

	<!-- Create Attribute -->
	<xsl:attribute name="{name(.)}">
		<xsl:value-of select="." />
	</xsl:attribute>
	
</xsl:template>

<!-- 
	Adjust headline hierarchy 
-->
<xsl:template match="h1 | h2 | h3 | h4" mode="ninja" priority="1" >

	<!-- Get level -->
	<xsl:param name="level" select="0" />
	
	<!-- Change hierarchy -->
	<xsl:element name="h{substring-after(name(), 'h') + $level}">
		<xsl:apply-templates select="* | @* | text()" />
	</xsl:element>
	
</xsl:template>

</xsl:stylesheet>

Discuss this XSLT Utility

Symphony • Open Source XSLT CMS

Server Requirements

  • PHP 5.3-5.6 or 7.0-7.3
  • PHP's LibXML module, with the XSLT extension enabled (--with-xsl)
  • MySQL 5.5 or above
  • An Apache or Litespeed webserver
  • Apache's mod_rewrite module or equivalent

Compatible Hosts

Sign in

Login details