<xsl:stylesheet version="1.0"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:xt="http://www.jclark.com/xt"
  extension-element-prefixes="xt">

<xsl:param name="interval" select="5"/>

<xsl:variable name="total" select="count(/pictures/picture)"/>
<xsl:variable name="plenty">
  <xsl:choose>
    <xsl:when test="$total > $interval">true</xsl:when>
    <xsl:otherwise/>
  </xsl:choose>
</xsl:variable>
<xsl:variable name="document" select="/pictures/picture[position() mod $interval = 1]"/>
<xsl:variable name="pages">
 <xsl:choose>
  <xsl:when test="$interval > 1"><xsl:value-of select="count($document)"/></xsl:when>
  <xsl:otherwise><xsl:value-of select="$total"/></xsl:otherwise>
 </xsl:choose>
</xsl:variable>


<xsl:template match="/">

<xsl:choose>
 <xsl:when test="$interval > 1">
  <xsl:for-each select="$document">
   <xsl:call-template name="documents"/>
  </xsl:for-each>
 </xsl:when>
 <xsl:otherwise>
  <xsl:for-each select="/pictures/picture">
   <xsl:call-template name="documents"/>
  </xsl:for-each>
 </xsl:otherwise>
</xsl:choose>

<xt:document href="all.html">
  <xsl:call-template name="html">
    <xsl:with-param name="set" select="/pictures/picture"/>
    <xsl:with-param name="multiple" select="'false'"/>
  </xsl:call-template>
</xt:document>

</xsl:template>


<xsl:template name="documents">

  <xsl:choose>
    <xsl:when test="position() = 1">
      <xt:document href="index.html"><xsl:call-template name="html"/></xt:document>
    </xsl:when>
    <xsl:otherwise>
      <xt:document href="pictures{$pages - position() + 1}.html"><xsl:call-template name="html"/></xt:document>
    </xsl:otherwise>
  </xsl:choose>

</xsl:template>





<xsl:template name="html">
  <xsl:variable name="page" select="position()"/>
  <xsl:param name="set" select="/pictures/picture[position() > $interval * ($page - 1) and position() &lt;= $interval * $page]"/>
  <xsl:param name="multiple">
    <xsl:choose>
      <xsl:when test="$total > $interval">true</xsl:when>
      <xsl:otherwise/>
    </xsl:choose>
  </xsl:param>
  <xsl:variable name="thisPage" select="$pages - $page + 1"/>

<html>
<head>
   <title>Sammy's LiveJournal</title>


</head>
<body bgcolor="#6666CC" vlink="#500050" text="#000000" link="#000050" alink="#FF00C0">
<table bgcolor="#FFFFFF" width="100%" height="95%" cellpadding="5">
<tr valign="TOP"><td align="left">

<img width="99" height="100" vspace="2" align="RIGHT" hspace="2">
  <xsl:attribute name="src">
    <xsl:choose>
      <xsl:when test="$page mod 2 = 0">thumbnail.jpg</xsl:when>
      <xsl:otherwise>thumbnail2.jpg</xsl:otherwise>
    </xsl:choose>
  </xsl:attribute>
</img>
<font size="+2" color="#8b1A1A" face="Arial,Helvetica">Sammy's LiveJournal</font>&#160;&#160;<b><tt><a href="pictures.xml">[View XML source]</a><xsl:text> </xsl:text><a href="pictures.xsl">[View XSLT stylesheet]</a></tt></b><font size="1"><br/>

<br/></font>
<b><tt>
<a href="http://samuel.livejournal.com">[Most Recent Entries]</a><xsl:text> </xsl:text>
<a href="http://samuel.livejournal.com/calendar">[Calendar View]</a><xsl:text> </xsl:text>
<a href="http://samuel.livejournal.com/friends">[Friends]</a><xsl:text> </xsl:text>
[Most Recent Photos]
</tt></b>

<p>
<xsl:choose>
  <xsl:when test="$page = 1">Below are the <b><xsl:value-of select="count($set)"/></b> most recent photos posted in <a href="http://www.livejournal.com/userinfo.bml?user=samuel">Sammy</a>'s photo album:</xsl:when>
  <xsl:otherwise>Below are <b><xsl:value-of select="count($set)"/></b> photos, after skipping by the <b><xsl:value-of select="$interval * ($page - 1)"/></b> most recent ones posted in <a href="http://www.livejournal.com/userinfo.bml?user=samuel">Sammy</a>'s photo album:</xsl:otherwise>
</xsl:choose>

<br/>

<!--
<xsl:if test="$page != last()"><small><a href="pictures1.html">jump to the beginning</a></small>
<xsl:if test="$page != 1"> | </xsl:if></xsl:if>
<xsl:if test="$page != 1"><small><a href="index.html">jump to the end</a></small></xsl:if>
-->

<xsl:choose>
  <xsl:when test="$multiple = 'true'"><small><a href="all.html">Click here to see all <xsl:value-of select="$total"/> pictures on one page!!</a></small></xsl:when>
  <xsl:when test="$plenty = 'true'"><small><a href="index.html">Click here to go back to the normal view</a></small></xsl:when>
  <xsl:otherwise/>
</xsl:choose>

<br clear="BOTH" />
<ul>

<!--
<xsl:variable name="nav">
<xsl:if test="$multiple='true'">
  <div align="center">[

<xsl:if test="$page != last()">
<a href="pictures{$thisPage - 1}.html">&lt;&lt; Previous <xsl:choose><xsl:when test="position() = last() - 1"><xsl:value-of select="$total - $interval * $page"/></xsl:when><xsl:otherwise><xsl:value-of select="$interval"/></xsl:otherwise></xsl:choose></a>
</xsl:if>

<xsl:if test="$page != 1">
<xsl:if test="$page != last()"><xsl:text>&#160;-&#160;</xsl:text></xsl:if>
<xsl:choose>
  <xsl:when test="$thisPage = $pages - 1"><a href="index.html">Next <xsl:value-of select="$interval"/> &gt;&gt;</a></xsl:when>
  <xsl:otherwise><a href="pictures{$thisPage + 1}.html">Next <xsl:value-of select="$interval"/> &gt;&gt;</a></xsl:otherwise>
</xsl:choose>
</xsl:if>

  ]</div>
</xsl:if>
</xsl:variable>
-->


<xsl:call-template name="nav">
  <xsl:with-param name="multiple" select="$multiple"/>
  <xsl:with-param name="page" select="$page"/>
</xsl:call-template>

    <xsl:for-each select="$set">
      <h2 align="center"><xsl:value-of select="@title"/></h2>
      <div align="center"><img src="{@src}"/></div>
      <div align="center"><xsl:value-of select="."/></div>
    </xsl:for-each>
<br/>

<xsl:call-template name="nav">
  <xsl:with-param name="multiple" select="$multiple"/>
  <xsl:with-param name="page" select="$page"/>
</xsl:call-template>

</ul>
</p>
</td></tr>
</table>

<table align="right" bgcolor="#FFFFFF" cellpadding="5" cellspacing="0" border="0">
<tr>
<td><a href="http://www.livejournal.com/"><font face="Arial,Helvetica" size="-1">About LiveJournal.com</font></a></td></tr>
</table>

</body>
</html>
</xsl:template>

<xsl:template name="nav">
<xsl:param name="multiple"/>
<xsl:param name="page"/>
<xsl:if test="$multiple='true'">
<div align="center">
<xsl:choose>
 <xsl:when test="$interval > 1">
  <xsl:for-each select="$document">
   <xsl:call-template name="navBody">
     <xsl:with-param name="page" select="$page"/>
   </xsl:call-template>
  </xsl:for-each>
 </xsl:when>
 <xsl:otherwise>
  <xsl:for-each select="/pictures/picture">
   <xsl:call-template name="navBody">
     <xsl:with-param name="page" select="$page"/>
   </xsl:call-template>
  </xsl:for-each>
 </xsl:otherwise>
</xsl:choose>
</div>
</xsl:if>
</xsl:template>

<xsl:template name="navBody">
      <xsl:param name="page"/>
      <xsl:choose>
        <xsl:when test="position() = $pages - $page + 1">
          <xsl:text>&#160;&#160;&#160;</xsl:text>
          <font size="+3"><xsl:value-of select="position()"/></font>
          <xsl:text>&#160;&#160;&#160;</xsl:text>
          <xsl:choose>
            <xsl:when test="position() mod 10 = 0"><br/></xsl:when>
            <xsl:when test="position() != last()">|</xsl:when>
            <xsl:otherwise/>
          </xsl:choose>
        </xsl:when>
        <xsl:otherwise>
          <xsl:text>&#160;&#160;&#160;</xsl:text>
          <a>
            <xsl:attribute name="href">
              <xsl:choose>
                <xsl:when test="position() = last()">index.html</xsl:when>
                <xsl:otherwise>pictures<xsl:value-of select="position()"/>.html</xsl:otherwise>
              </xsl:choose>
            </xsl:attribute>
            <xsl:value-of select="position()"/>
          </a>
          <xsl:text>&#160;&#160;&#160;</xsl:text>
          <xsl:choose>
            <xsl:when test="position() mod 10 = 0"><br/></xsl:when>
            <xsl:when test="position() != last()">|</xsl:when>
            <xsl:otherwise/>
          </xsl:choose>
        </xsl:otherwise>
      </xsl:choose>
</xsl:template>

</xsl:stylesheet>