XSLT

XSLT - Still not dead!

You want to create the static content for your website.
You want to create the layout of the site once, and then just write the content for each page?
You don't want to have to run up and maintain a server like PHP or Tomcat to generate the content server side?
You don't want to use some flaky HTML5 Javascript automagic that is only supported by one particular browser?
You thought about writing a clever shell script that does seaching and replacing of tags in other files but realised all of a sudden that, perhaps someone else might already have done that?
Then you had a gnawing memory... what was it called again.. XSL something.. Stylesheets.. No that's CSS isn't it?

What you want to write is something like this:
             
<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="./xsl/main.xsl"?>
<html>	
	<head>		    	   		
	    <title>This page's title</title>	    
	</head>
	
	<body>
		<heading>this page's heading!</heading>
		<logo>
		    <src>/images/logos/this_pages_logo.svg</src>
		</logo>	
		
		<content>
			<!-- Content Here! -->	
		</content>
	</body>
</html>            
        	
        

Then use something like this to transform your xml into HTML :
             
<?xml version="1.0"?>

<!-- Richard Mark Senior 2013 -->
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0">
<xsl:output version="2.0" method="html" media-type="text/html" encoding="UTF-8" omit-xml-declaration="yes"/>

<xsl:template match="/">
<html>
	<head>
		<META http-equiv="pragma" content="no-cache" />
		<META http-equiv="expires" content="0" />
						
		<!-- html may or may not contain a <description/> tag -->
     	<xsl:choose>
      		<xsl:when test="html/head/description">
				<META name="description"><xsl:attribute name="content"><xsl:value-of select="html/head/description"/></xsl:attribute></META>	
      		</xsl:when>
      		<xsl:otherwise> 			
				<META name="description" content="Richard Mark Senior" />
      		</xsl:otherwise>
     	</xsl:choose>
			
		<!-- html may or may not contain a <keywords/> tag -->
     	<xsl:choose>
      		<xsl:when test="html/head/keywords">
				<META name="keywords"><xsl:attribute name="content"><xsl:value-of select="html/head/keywords"/></xsl:attribute></META>	
      		</xsl:when>
      		<xsl:otherwise>
				<META name="keywords" content="Richard Mark Senior website java developer software rubik cube speedcube guitar guitarist fabulous rocking sturgeons" />
      		</xsl:otherwise>
     	</xsl:choose>			
		
	
		<!--  HEAD may contain one or more <stylesheet><href>/blah.css</href></stylesheet> tags-->
     	<xsl:choose>
      		<xsl:when test="html/head/stylesheet">		
				<xsl:for-each select="html/head/stylesheet">
					<link REL="stylesheet" type="text/css">
						<xsl:attribute name="href">
							<xsl:value-of select="href" />
						</xsl:attribute>			
					</link>
		    	</xsl:for-each>
      		</xsl:when>
      		<xsl:otherwise> 			
				<!-- add the default stylesheet if no stylesheets are specified-->
				<link rel="stylesheet" type="text/css" href="/css/main.css" />
      		</xsl:otherwise>
     	</xsl:choose>
		    	
    	    
		<!--  HEAD may contain one or more <script><type>text/javascript</type><src>/scripts/main.js</src></script> tags-->
     	<xsl:choose>
      		<xsl:when test="html/head/script">		
				<xsl:for-each select="html/head/script">
					<script>
						<xsl:attribute name="type">
							<xsl:value-of select="type"/>
						</xsl:attribute>
						<xsl:attribute name="src">
							<xsl:value-of select="src"/>
						</xsl:attribute>
					</script>
		    	</xsl:for-each> 
    	   	</xsl:when>
      		<xsl:otherwise> 			
				<!-- add the default javascript library if no libraries are specified-->
				<!-- <script type="text/javascript" src="/scripts/main.js" />  -->				
      		</xsl:otherwise>
     	</xsl:choose>
    	
    	<!-- head may or may not contain <title></title> -->
     	<xsl:choose>
      		<xsl:when test="html/head/title">
      			<xsl:comment><xsl:value-of select="html/head/title"/></xsl:comment>		
				<title><xsl:value-of select="html/head/title"/></title>
      		</xsl:when>
      		<xsl:otherwise>
      		    <xsl:comment>Richard Mark Senior</xsl:comment>		
				<title>Richard Mark Senior</title>
      		</xsl:otherwise>
     	</xsl:choose>
     	
     	<xsl:value-of select="html/head/extra" disable-output-escaping="yes" />
    </head>

    <body>
    	<!-- body may or may not contain an <background>./images/background.gif</background> tag -->
     	<xsl:choose>
      		<xsl:when test="html/body/background">	
				<xsl:attribute name="background"><xsl:value-of select="html/body/background"/></xsl:attribute>    				
      		</xsl:when>
      		<xsl:otherwise>
				<xsl:attribute name="background">/images/background.gif</xsl:attribute>    			      		
      		</xsl:otherwise>
     	</xsl:choose>    
    
    	<!-- body may or may not contain an <onLoad></onLoad> tag -->
    	<xsl:if test="html/body/onLoad">
			<xsl:attribute name="onload">
				<xsl:value-of select="html/body/onLoad"/>				
			</xsl:attribute>    
    	</xsl:if>
    	
    	<CENTER>

    	<TABLE WIDTH="60%" CELLSPACING="0" CELLPADDING="0" BORDER="0">
			<TR>
				<TD class="maintitle">Richard Mark Senior</TD>
				<TD rowspan="2" align="right">
					<xsl:if test="html/body/logo">									
						<img class="logo">
							<xsl:attribute name="src">
								<xsl:value-of select="html/body/logo/src"/>
							</xsl:attribute>
							<xsl:attribute name="alt">
								<xsl:value-of select="html/body/logo/alt"/>
							</xsl:attribute>						
						</img>
					</xsl:if>	
				</TD>
			</TR>
			<TR><TD class="strapline">Providing Internet content of nearly zero value since 1996<br/><br/></TD></TR>
		</TABLE>
		
		
		<TABLE WIDTH="60%" CELLPADDING="0" CELLSPACING="0" height="80%">
			<TR>
		 		<TD WIDTH="10%" VALIGN="TOP" ALIGN="LEFT">
		 			<TABLE WIDTH="100%" CELLSPACING="0" CELLPADDING="0">
						<xsl:for-each select="html/body/nav">
							<TR>
								<TD class="nav">
									<a class="nav">
										<xsl:attribute name="href">
											<xsl:value-of select="href"/>
										</xsl:attribute>
										<xsl:attribute name="title">
											<xsl:value-of select="alt"/>
										</xsl:attribute>
										<xsl:value-of select="text"/>																									
									</a>
								</TD>
							</TR>
				    	</xsl:for-each>
				    	<!-- if there are no navbar items then add the standard navbar -->
				    	<xsl:if test="not(html/body/nav)">
					    	<TR><TD class="nav"><a class="nav" href="/" title="home">home</a></TD></TR>
					    	<TR><TD class="nav"><a class="nav" href="/blog/" title="blog">blog</a></TD></TR>
					    	<TR><TD class="nav"><a class="nav" href="/resume/" title="CV">resume</a></TD></TR>
					    	<TR><TD class="nav"><a class="nav" href="/cube/" title="rubiks cube">cube</a></TD></TR>
					    	<TR><TD class="nav"><a class="nav" href="/photos/" title="photos">photos</a></TD></TR>
				    	</xsl:if>				    	  			   					   		
				    					 			
		 			</TABLE>
		 		</TD>
		 		<TD width="90%" VALIGN="top" ALIGN="left">
		 			<H1><xsl:value-of select="html/body/heading"/></H1>
		 			<table width="100%" height="100%" cellspacing="0" cellpadding="0">
		 			 	<tr>		 			 	
		 			 		<td align="left" valign="top" class="pageContent" height="100%">
		 			 			<div class="borderDiv">
		 			 				<xsl:value-of select="html/body/content" disable-output-escaping="yes" />
		 			 				<br/>
				 			 			<xsl:if test="html/body/content/next or html/body/content/prev">
				 			 				<table width="100%" cellpadding="0" cellspacing="0">
				 			 					<tr>
				 			 						<td align="left">
				 			 							<xsl:if test="html/body/content/prev">
				 			 				<comments/>				<a>
																<xsl:attribute name="href">
																	<xsl:value-of select="html/body/content/prev"/>
																</xsl:attribute>
																<xsl:attribute name="title">
																	<xsl:value-of select="previous"/>
																</xsl:attribute>
																<xsl:text>previous</xsl:text>
															</a>		 			 								
				 			 							</xsl:if>
				 			 						</td>
				 			 						<td align="right">
				 			 							<xsl:if test="html/body/content/prev">
															<a>
																<xsl:attribute name="href">
																	<xsl:value-of select="html/body/content/next"/>
																</xsl:attribute>
																<xsl:attribute name="title">
																	<xsl:value-of select="next"/>
																</xsl:attribute>
																<xsl:text>next</xsl:text>
															</a>		 			 								
				 			 							</xsl:if>
				 			 						</td>
				 			 					</tr>
				 			 				</table>
				 			 			</xsl:if>			 			 						 			 				
		 			 			</div>	 			 					 			 			
		 			 		</td>
		 			 	</tr>
		 			 	<tr>
		 			 		<td align="right" class="footer">	
		 			 			<xsl:value-of select="document-uri(.)" />	 			 			
		 			 			<xsl:text>&#160;&#169;</xsl:text>2013 Richard Mark Senior
		 			 		</td>
		 			 	</tr>
		 			</table>
				</TD>								
		  	</TR>
		</TABLE>
		</CENTER>		
		
    </body>
</html>
</xsl:template>  
</xsl:stylesheet>            
        	
        

Using a simple method, perhaps like a MAVEN plugin such as the one below?
I will just let you know now though, that you can probably avoid all this by using maven's SITE plugin with a bespoke skin (see elsewhere on this site) :)
             
<plugin>
	<groupId>org.codehaus.mojo</groupId>
	<artifactId>xml-maven-plugin</artifactId>
	<executions>
		<execution>
			<goals>
				<goal>transform</goal>
			</goals>
			<phase>site</phase>
		</execution>
	</executions>
	<configuration>
		<transformationSets>
			<transformationSet>
				<outputDir>${project.build.directory}/site</outputDir>
				<includes>
					<include>**/*.xml</include>
				</includes>
				<excludes>
					<exclude>**/nav.xml</exclude>
				</excludes>
				<dir>${project.basedir}/src/main/resources/xslt</dir>
				<fileMappers>
					<fileMapper
						implementation="org.codehaus.plexus.components.io.filemappers.FileExtensionMapper">
						<targetExtension>.html</targetExtension>
					</fileMapper>
				</fileMappers>
				<stylesheet>${project.basedir}/src/main/resources/xslt/xsl/main.xsl</stylesheet>
			</transformationSet>
		</transformationSets>
	</configuration>
	<dependencies>
		<dependency>
			<groupId>net.sf.saxon</groupId>
			<artifactId>saxon</artifactId>
			<version>8.7</version>
		</dependency>
	</dependencies>
</plugin>