Pages and Page Transformations |
You can use any XML language for the data files. Of course, the XSLT files have to be adapted to the XML structure.
Simple Pages
This is the XML file for the homepage of the Bonebreaker site:
<?xml version="1.0"?>
<page>
<title>Welcome to Bonebreaker Bikes!</title>
</page>
It is called with the URL /bonebreaker/home/home.section and therefore transformed with the XSLT file section.xsl:
<?xml version="1.0"?>
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version='1.0'
xmlns:xlink="http://www.w3.org/1999/xlink"
xmlns:site="http://www.bonebreakerbikes.com"/>
For parameter descriptions see The Sitemap.
<xsl:param name="toc-file"/> <xsl:param name="section"/> <xsl:param name="base-url"/> <xsl:template match="page"/>
Apply the templates from the XML page.
<xsl:apply-templates/>
Apply the templates from the TOC file to create the local menu for this section.
<xsl:apply-templates select="document($toc-file)/*"/> </xsl:template>
Page: Display the page title.
<xsl:template match="title"> <h2><xsl:apply-templates/></h2> </xsl:template>
TOC: Remove all other sections.
<xsl:template match="site:section[@name!=$section]"> </xsl:template>
TOC: Match the current section and create the list of items.
<xsl:template match="site:section[@name=$section]">
<ul>
<xsl:apply-templates select="site:page"/>
</ul>
</xsl:template>
TOC: Create a list item for a page.
<xsl:template match="site:page">
<li>
<xsl:choose>
External link (do not include path information)
<xsl:when test="@ext='true'">
<a href="{@xlink:href}"><xsl:apply-templates/></a>
</xsl:when>
Internal link (include path information)
<xsl:otherwise>
<a href="{$base-url}/{$section}/{@xlink:href}">
<xsl:apply-templates/>
</a>
</xsl:otherwise>
</xsl:choose>
</li>
</xsl:template>
</xsl:stylesheet>
Standard Pages
This is the XSLT file page.xsl that is used to transform a simple page. It does not yet contain any template matchers except for the page title.
<?xml version="1.0"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version='1.0' xmlns:xlink="http://www.w3.org/1999/xlink"> <xsl:template match="page"> <xsl:apply-templates/> </xsl:template> <xsl:template match="title"> <h2><xsl:apply-templates/></h2> </xsl:template> </xsl:stylesheet>
Bike Pages
This is a sample XML file to describe a bicycle:
<?xml version="1.0"?>
<bike>
<name>Thighbreaker Comp</name>
<purpose>Cross Country Competition</purpose>
<frame>
<travel>80</travel>
</frame>
</bike>
This XSLT file (bike.xsl) is used to transform a bike file into HTML code:
<?xml version='1.0'?>
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version='1.0'
xmlns:xlink="http://www.w3.org/1999/xlink">
<xsl:template match="bike">
<xsl:apply-templates select="child::*"/>
</xsl:template>
<xsl:template match="name">
<h2><xsl:apply-templates/></h2>
</xsl:template>
<xsl:template match="purpose">
<p><strong>Purpose:</strong>&#160;<xsl:apply-templates/></p>
</xsl:template>
<xsl:template match="frame">
<p><strong>Frame:</strong></p>
<ul>
<xsl:apply-templates/>
</ul>
</xsl:template>
<xsl:template match="travel">
<li>Travel: <xsl:apply-templates/> mm</li>
</xsl:template>
</xsl:stylesheet>




