]> git.draconx.ca Git - homepage.git/blobdiff - layouts/default.xsl
Use a denser style for gallery images.
[homepage.git] / layouts / default.xsl
index a97f784c2d3e2cb63a4446e4b6eaadf0ed2f7f21..7325708557a89089d76469a80a5fb11b9f78f610 100644 (file)
@@ -22,8 +22,9 @@
   xmlns:xhtml='http://www.w3.org/1999/xhtml'
   xmlns:xsl='http://www.w3.org/1999/XSL/Transform'
   xmlns:func='http://exslt.org/functions'
+  xmlns:exslt='http://exslt.org/common'
   xmlns:f='http://draconx.ca/my-functions'
-  extension-element-prefixes='func f'
+  extension-element-prefixes='exslt func f'
   exclude-result-prefixes='xhtml'>
 
 <xsl:import href='layouts/functions.xsl' />
   <xsl:copy><xsl:apply-templates select='node()|@*' /></xsl:copy>
 </xsl:template>
 
+<xsl:template name='notransform' mode='notransform' match='node()|@*'>
+  <xsl:copy>
+    <xsl:apply-templates mode='notransform' select='node()|@*' />
+  </xsl:copy>
+</xsl:template>
+
 <!--
   Nokogiri's pretty-printer is a bit weird.  Regardless of the indentation
   setting, if an element has no child text nodes then it will be pretty-
 </xsl:template>
 
 <xsl:template match='license'>
+  <xsl:variable name='node' select='.' />
   <p>
-    <xsl:text>Copying and distribution of this material</xsl:text>
+    <xsl:choose>
+      <xsl:when test='/document/image[license != $node]'>
+        <xsl:text>Except as otherwise noted, copying</xsl:text>
+      </xsl:when>
+      <xsl:otherwise>Copying</xsl:otherwise>
+    </xsl:choose>
+    <xsl:text> and distribution of this material</xsl:text>
     <xsl:if test='normalize-space(modification-allowed)="yes"'>
       <xsl:text>, with or without modification,</xsl:text>
     </xsl:if>
 </xsl:template>
 
 <xsl:template name='image-attribution'>
-<!--
-  <xsl:variable name='x' select='/document/image[copyright-holder="Nick Bowler"][1]' />
-  <xsl:variable name='y' select='/document/image[copyright-holder="Nick Bowler"][4]' />
--->
   <xsl:variable name='images-fragment'>
     <xsl:for-each select='/document/image'>
       <xsl:sort select='number(copyright-holder = /document/copyright-holder)'
   </xsl:if>
 </xsl:template>
 
+<xsl:template name='imgpara' match='xhtml:p[count(*)=1]
+                                           [normalize-space(text())=""]
+                                           [descendant::xhtml:img]'>
+  <xsl:copy>
+    <xsl:apply-templates select='@*[local-name() != "class"]' />
+    <xsl:attribute name='class'>
+      <xsl:if test='@class'>
+        <xsl:value-of select='concat(@class, " ")' />
+      </xsl:if>
+      <xsl:text>img</xsl:text>
+    </xsl:attribute>
+    <xsl:apply-templates select='node()' />
+  </xsl:copy>
+</xsl:template>
+
+<xsl:key name='gallery'
+  match='xhtml:html/xhtml:p[descendant::*[@generate-gallery]]'
+  use='generate-id(
+        ( ( preceding-sibling::*[not(descendant::*[@generate-gallery])][1]
+          /following-sibling::* ) | self::* ) [1])' />
+
+<xsl:template match='@generate-gallery' />
+<xsl:template match='xhtml:html/xhtml:p[descendant::*[@generate-gallery]]' />
+<xsl:template match='xhtml:html/xhtml:p[key("gallery", generate-id(.))]'>
+  <xsl:variable name='images' select='key("gallery", generate-id(.))' />
+  <xsl:choose>
+    <xsl:when test='count($images) > 1'>
+      <div class='gallery'>
+        <xsl:for-each select='$images'>
+          <xsl:call-template name='imgpara' />
+        </xsl:for-each>
+      </div>
+    </xsl:when>
+    <xsl:otherwise>
+      <xsl:call-template name='imgpara' />
+    </xsl:otherwise>
+  </xsl:choose>
+</xsl:template>
+
 <xsl:template match='/'>
   <html>
     <head>
       <div id='footer'>
         <xsl:apply-templates select='/document/copyright' />
         <xsl:apply-templates select='/document/license' />
+        <xsl:if test='/document/image'>
+          <xsl:call-template name='image-attribution' />
+        </xsl:if>
         <xsl:apply-templates select='/document/source' />
       </div>
     </body>