]> git.draconx.ca Git - homepage.git/blob - layouts/imginfo.xsl
Add separator rows to the sorted part of clicky tables.
[homepage.git] / layouts / imginfo.xsl
1 <?xml version='1.0' encoding='UTF-8' ?>
2 <!--
3   Nick's web site: Image description page formatter
4
5   Copyright © 2020 Nick Bowler
6
7   This program is free software: you can redistribute it and/or modify
8   it under the terms of the GNU General Public License as published by
9   the Free Software Foundation, either version 3 of the License, or
10   (at your option) any later version.
11
12   This program is distributed in the hope that it will be useful,
13   but WITHOUT ANY WARRANTY; without even the implied warranty of
14   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15   GNU General Public License for more details.
16
17   You should have received a copy of the GNU General Public License
18   along with this program.  If not, see <https://www.gnu.org/licenses/>
19 -->
20 <xsl:stylesheet version='1.0'
21   xmlns='http://www.w3.org/1999/xhtml'
22   xmlns:xhtml='http://www.w3.org/1999/xhtml'
23   xmlns:xsl='http://www.w3.org/1999/XSL/Transform'
24   exclude-result-prefixes='xhtml'>
25
26 <xsl:output method='xml' encoding='UTF-8' indent='yes'
27   omit-xml-declaration='yes' />
28
29 <xsl:template match='node()|@*'>
30   <xsl:copy><xsl:apply-templates select='node()|@*' /></xsl:copy>
31 </xsl:template>
32
33 <xsl:template name='exif'>
34   <xsl:param name='node' select='.' />
35   <xsl:param name='name' select='local-name($node)' />
36
37   <tr>
38     <td><xsl:value-of select='$name' /></td>
39     <td><xsl:value-of select='$node' /></td>
40   </tr>
41 </xsl:template>
42 <xsl:template match='exif'>
43   <h2>Metadata</h2>
44   <table>
45     <thead>
46       <tr><th>Attribute</th><th>Value</th></tr>
47     </thead>
48     <tbody>
49       <xsl:call-template name='exif'>
50         <xsl:with-param name='node' select='make' />
51         <xsl:with-param name='name' select='"Camera make"' />
52       </xsl:call-template>
53       <xsl:call-template name='exif'>
54         <xsl:with-param name='node' select='model' />
55         <xsl:with-param name='name' select='"Camera model"' />
56       </xsl:call-template>
57       <xsl:call-template name='exif'>
58         <xsl:with-param name='node' select='date_time_original' />
59         <xsl:with-param name='name' select='"Date taken"' />
60       </xsl:call-template>
61       <xsl:call-template name='exif'>
62         <xsl:with-param name='node' select='concat(exposure_time, "s")' />
63         <xsl:with-param name='name' select='"Shutter speed"' />
64       </xsl:call-template>
65       <xsl:call-template name='exif'>
66         <xsl:with-param name='node' select='concat("f/", f_number)' />
67         <xsl:with-param name='name' select='"Aperture"' />
68       </xsl:call-template>
69       <xsl:call-template name='exif'>
70         <xsl:with-param name='node' select='exposure_bias_value' />
71         <xsl:with-param name='name' select='"Exposure compensation"' />
72       </xsl:call-template>
73       <xsl:call-template name='exif'>
74         <xsl:with-param name='node' select='concat(focal_length, "mm")' />
75         <xsl:with-param name='name' select='"Focal length"' />
76       </xsl:call-template>
77       <xsl:call-template name='exif'>
78         <xsl:with-param name='node' select='flash' />
79         <xsl:with-param name='name' select='"Flash"' />
80       </xsl:call-template>
81       <xsl:call-template name='exif'>
82         <xsl:with-param name='node' select='iso_speed_ratings' />
83         <xsl:with-param name='name' select='"ISO speed rating"' />
84       </xsl:call-template>
85       <xsl:call-template name='exif'>
86         <xsl:with-param name='node' select='exposure_program' />
87         <xsl:with-param name='name' select='"Exposure program"' />
88       </xsl:call-template>
89       <xsl:call-template name='exif'>
90         <xsl:with-param name='node' select='metering_mode' />
91         <xsl:with-param name='name' select='"Metering mode"' />
92       </xsl:call-template>
93     </tbody>
94   </table>
95 </xsl:template>
96
97 <xsl:template match='variant'>
98   <li>
99     <a href='{uri}'>
100       <xsl:value-of
101         select='concat(name, " (", width, "x", height, ", ", filesize, ")")' />
102     </a>
103   </li>
104 </xsl:template>
105
106 <xsl:template match='xhtml:description'>
107   <h2 id='desc'>Description</h2>
108   <xsl:choose>
109     <xsl:when test='*'>
110       <xsl:apply-templates select='node()' />
111     </xsl:when>
112     <xsl:otherwise>
113       <p><xsl:apply-templates select='node()' /></p>
114     </xsl:otherwise>
115   </xsl:choose>
116 </xsl:template>
117
118 <xsl:template match='/'>
119   <p>
120     <img src='{/image/variant[1]/uri}' alt=''
121       width='{/image/variant[1]/width}'
122       height='{/image/variant[1]/height}'>
123       <xsl:if test='/image/xhtml:description'>
124         <xsl:attribute name='longdesc'>#desc</xsl:attribute>
125       </xsl:if>
126     </img>
127   </p>
128   <xsl:apply-templates select='/image/xhtml:description' />
129   <h2>Files</h2>
130   <ul>
131     <xsl:apply-templates select='/image/variant'>
132       <xsl:sort select='width*height' order='ascending' data-type='number' />
133     </xsl:apply-templates>
134   </ul>
135   <xsl:apply-templates select='/image/exif' />
136 </xsl:template>
137
138 </xsl:stylesheet>