Česky
Kamil Dudka

Web components

File detail

Name:DownloadSiteMapBuilder.xsl [Download]
Location: src > page
Size:3.0 KB
Last modification:2007-12-11 16:09

Source code

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:output
             method="xml"
             version="1.0"
             encoding="utf-8"
             indent="no"
             omit-xml-declaration="yes"
             />
  <xsl:strip-space elements="*"/>
 
  <xsl:template match="/">
    <xsl:apply-templates mode="init"/>
  </xsl:template>
 
  <!-- match root element -->
  <xsl:template match="/page" mode="init">
    <!-- Initialize PHP environment -->
    <xsl:processing-instruction name="php">
      <xsl:text>
$pageDir = $docRoot.$config->pageDir();
$tplDir = $config->smartyConf['template_dir'];
$syslLastMod = 0;
$sysLastMod = max($sysLastMod, filemtime($pageDir.'/PageServer.xsl'));
$sysLastMod = max($sysLastMod, filemtime($pageDir.'/PageServer_init.xsl'));
$sysLastMod = max($sysLastMod, filemtime($tplDir.'/pageInit.tpl'));
$sysLastMod = max($sysLastMod, filemtime($tplDir.'/pageBodyInit.tpl'));
$sysLastMod = max($sysLastMod, filemtime($tplDir.'/pageEnd.tpl'));
      </xsl:text>
    </xsl:processing-instruction>
    <!-- root element -->
    <urlset
      xmlns="http://www.google.com/schemas/sitemap/0.84"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="http://www.google.com/schemas/sitemap/0.84
                          http://www.google.com/schemas/sitemap/0.84/sitemap.xsd">
      <xsl:call-template name="url"/>
    </urlset>
  </xsl:template>
 
  <!-- parse subpage recursively -->
  <!-- TODO: avoid loops? -->
  <xsl:template match="subpage/text()">
    <xsl:for-each select="document(concat(self::text(),'.xml'))">
      <xsl:apply-templates/>
    </xsl:for-each>
  </xsl:template>
 
  <!-- Include all visible pages -->
  <xsl:template match="page[not(@visible='no')]" name="url">
    <!-- xmlns used to work around strange behavior of XSLT processor -->
    <url xmlns="http://www.google.com/schemas/sitemap/0.84">
      <loc>
        <xsl:processing-instruction name="php">
          <xsl:text>echo $config->webRoot().'/';</xsl:text>
        </xsl:processing-instruction>
        <xsl:if test="@id!='index'">
          <xsl:value-of select="@id"/>
        </xsl:if>
      </loc>
      <lastmod>
        <xsl:processing-instruction name="php">
          <xsl:text>echo date('Y-m-d', max($sysLastMod, filemtime($pageDir.'/'.'</xsl:text>
          <xsl:value-of select="@id"/>
          <xsl:text>.xml')));</xsl:text>
        </xsl:processing-instruction>
      </lastmod>
      <!-- use changefreq attribute of page element -->
      <xsl:if test="@changefreq">
        <changefreq>
          <xsl:value-of select="@changefreq"/>
        </changefreq>
      </xsl:if>
      <!-- use priority attribute of page element -->
      <xsl:if test="@priority">
        <priority>
          <xsl:value-of select="@priority"/>
        </priority>
      </xsl:if>
    </url>
    <xsl:apply-templates/>
  </xsl:template>
 
  <!-- Ignore other page content -->
  <xsl:template match="MainPage|name|pageInit" />
 
</xsl:stylesheet>