Turn MyMiniCity.com XML into XHTML via XSLT

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

  <!--
  This XSLT stylesheet turns XML output from MyMiniCity.com into nice XHTML.
  Feel free to translate it from German to your language, should be pretty
  straightforward.

  To make it all work, the XSL processing instruction has to be injected into
  the XML document.  For that purpose, you might want to use the following
  piece of PHP code (although nearly any language should do the trick):

    <?php
    $url = 'http://YOURCITY.myminicity.com/xml';
    $pi = '<?xml-stylesheet type="text/xsl" href="citystats.xsl"?>';
    $xml = file_get_contents($url);
    $pos = strpos($xml, '>') + 1;
    header('Content-Type: text/xml');
    echo substr_replace($xml, "\n" . $pi . "\n", $pos, 0);
    ?>

  Be sure to adjust the URL of the first `xsl:variable` and the above snippet
  to your city.

  Copyright (c) March 2008 Jochen Kupperschmidt
  -->

  <xsl:variable name="baseURL" select="'http://YOURCITY.myminicity.com/'"/>

  <xsl:template match="/city">
<html>
  <head>
    <title>City Stats</title>
    <style type="text/css">
      body {
        font-family: Verdana, Arial, sans;
        font-size: 85%;
        text-align: center;
      }
      p {
        font-size: 120%;
      }
      table {
        margin: 0 auto;
        text-align: left;
      }
      .percent {
        font-weight: bold;
        text-align: right;
      }
      .warning {
        color: red;
      }
    </style>
  </head>
  <body>
    <h1>City Stats</h1>
    <p><strong><xsl:value-of select="population"/></strong> Einwohner
      (<a href="{$baseURL}">einwandern</a>),
      Rang <xsl:value-of select="ranking"/></p>
    <table>
      <xsl:call-template name="stats-row">
        <xsl:with-param name="label" select="'Arbeitslosigkeit'"/>
        <xsl:with-param name="percent" select="unemployment"/>
        <xsl:with-param name="type" select="'ind'"/>
        <xsl:with-param name="label-action" select="'Fabrik eröffnen'"/>
      </xsl:call-template>
      <xsl:call-template name="stats-row">
        <xsl:with-param name="type" select="'com'"/>
        <xsl:with-param name="label-action" select="'Gewerbe steigern'"/>
      </xsl:call-template>
      <xsl:call-template name="stats-row">
        <xsl:with-param name="label" select="'Verkehrsnetz'"/>
        <xsl:with-param name="percent" select="transport "/>
        <xsl:with-param name="type" select="'tra'"/>
        <xsl:with-param name="label-action" select="'Verkehrsnetz ausbauen'"/>
      </xsl:call-template>
      <xsl:call-template name="stats-row">
        <xsl:with-param name="label" select="'Kriminalität'"/>
        <xsl:with-param name="percent" select="criminality"/>
        <xsl:with-param name="type" select="'sec'"/>
        <xsl:with-param name="label-action" select="'Polizei verstärken'"/>
      </xsl:call-template>
      <xsl:call-template name="stats-row">
        <xsl:with-param name="label" select="'Umweltverschmutzung'"/>
        <xsl:with-param name="percent" select="pollution"/>
        <xsl:with-param name="type" select="'env'"/>
        <xsl:with-param name="label-action" select="'Parks bauen'"/>
      </xsl:call-template>
    </table>
  </body>
</html>
  </xsl:template>

  <xsl:template name="stats-row">
    <xsl:param name="label"/>
    <xsl:param name="percent"/>
    <xsl:param name="type"/>
    <xsl:param name="label-action"/>
    <xsl:variable name="hits" select="bases/@*[name() = $type]"/>
      <tr>
        <td><xsl:if test="$label"><xsl:value-of select="$label"/>:</xsl:if></td>
        <td class="percent">
          <xsl:if test="$percent">
          <span>
            <xsl:if test="($percent mod 100) != 0">
              <xsl:attribute name="class">warning</xsl:attribute>
            </xsl:if>
            <xsl:value-of select="$percent"/>%
          </span>
          </xsl:if>
        </td>
        <td>&#160;&#8594;&#160;
          <a href="{$baseURL}{$type}"><xsl:value-of select="$label-action"/></a>
          (<xsl:value-of select="$hits"/> Hit<xsl:if test="$hits != 1">s</xsl:if>)
        </td>
      </tr>
  </xsl:template>

</xsl:stylesheet>