Monthly archives

Sun 23 July 2006, , ,

Some enhancement for this weblog with the archives pages for the months of July and June. A future step’ll be to make un page for each tag. Now it’s only for Technorati. I should probably use the redirect extension. Here a little example :

The source file (source.xml):

<?xml version="1.0"?>
<feed>
   <entry>A</entry>
   <entry>B</entry>
   <entry>C</entry>
   <entry>D</entry>
</feed>

The template (chunk.xsl):

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0"
   xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
   xmlns:redirect="org.apache.xalan.xslt.extensions.Redirect"
   extension-element-prefixes="redirect">

<xsl:output method="xml" indent="yes"
   doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"
   doctype-public="-//W3C//DTD XHTML 1.0 Transitional//EN" />

<xsl:template match="/">
   <xsl:choose>
      <xsl:when test="element-available('redirect:write')">
         <xsl:for-each select="//entry">
            <redirect:write select="concat(., '.html')">
               <!-- The page of the entry -->
               <html>
                  <head>
                     <title><xsl:value-of select="." /></title>
                  </head>
                  <body>
                     <h1><xsl:value-of select="." /></h1>
                     <a href=".">Back</a>
                  </body>
               </html>
            </redirect:write>
         </xsl:for-each>
      </xsl:when>
      <xsl:otherwise>
         <xsl:message>Redirect extension isn't available</xsl:message>
      </xsl:otherwise>
   </xsl:choose>
   <!-- Output the main page -->
   <html>
      <head>
         <title>Main page</title>
      </head>
      <body>
         <h1>Main page</h1>
         <ol>
            <xsl:for-each select="//entry">
               <li>
                  <a href="{concat(., '.html')}">
                     <xsl:value-of select="." />
                  </a>
               </li>
            </xsl:for-each>
         </ol>
      </body>
   </html>
</xsl:template>

</xsl:stylesheet>

After a transformation (here using xsltproc): xsltproc chunk.xsl input.xml > index.html. You’ve got 5 files :

  • index.html
  • A.html
  • B.html
  • C.html
  • D.html

This kind of way of working enable you to work more globally. In the case of this blog, it should enable me to generate, with only one transformation, all the blog. It’ very useful for archives, entries or feeds where I only need to give to the XSL template a list of the entries. But I need more work to generate the page for each tags. It’s probably a two passes way.

Afin d’améliorer un peu ce blog, j’ai ajouté les archives mensuelles. Il me resterait à faire les pages selon les tags utilisés. Pour l’instant, je fais confiance à Technorati.

Sinon, je pense qu’il va me falloir utiliser l’extension redirect (voir l’exemple ci-dessus) afin d’améliorer la génération de ce blog et peut-être (dans un futur proche) la génération des pages par tags.

Digg it!, so del.icio.us, blogmarks, reddit.