atom2html.xslt 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!--
  3. iPhoto2Atom, extract images from iPhoto™ libraries
  4. Copyright (C) 2015-2016 Marcus Rohrmoser, http://purl.mro.name/iPhoto2Atom
  5. This program is free software: you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation, either version 3 of the License, or
  8. (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program. If not, see <http://www.gnu.org/licenses/>.
  15. Turn a atom photo feed into a html preview page.
  16. http://www.w3.org/TR/xslt/
  17. -->
  18. <xsl:stylesheet
  19. xmlns="http://www.w3.org/1999/xhtml"
  20. xmlns:a="http://www.w3.org/2005/Atom"
  21. xmlns:media="http://search.yahoo.com/mrss/"
  22. xmlns:georss="http://www.georss.org/georss"
  23. xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  24. exclude-result-prefixes="a media georss"
  25. version="1.0">
  26. <!-- replace linefeeds with <br> tags -->
  27. <xsl:template name="linefeed2br">
  28. <xsl:param name="string" select="''"/>
  29. <xsl:param name="pattern" select="'&#10;'"/>
  30. <xsl:choose>
  31. <xsl:when test="contains($string, $pattern)">
  32. <xsl:value-of select="substring-before($string, $pattern)"/><br class="br"/><xsl:comment>Why do we see 2 br on Safari and output/@method=html here? http://purl.mro.name/safari-xslt-br-bug</xsl:comment>
  33. <xsl:call-template name="linefeed2br">
  34. <xsl:with-param name="string" select="substring-after($string, $pattern)"/>
  35. <xsl:with-param name="pattern" select="$pattern"/>
  36. </xsl:call-template>
  37. </xsl:when>
  38. <xsl:otherwise>
  39. <xsl:value-of select="$string"/>
  40. </xsl:otherwise>
  41. </xsl:choose>
  42. </xsl:template>
  43. <xsl:template name="degrees">
  44. <xsl:param name="num" select="0"/>
  45. <xsl:choose>
  46. <xsl:when test="$num &lt; 0">-<xsl:call-template name="degrees"><xsl:with-param name="num" select="-$num"/></xsl:call-template></xsl:when>
  47. <xsl:when test="$num &gt;= 0">
  48. <xsl:variable name="deg" select="floor($num)"/>
  49. <xsl:variable name="min" select="floor(($num * 60) mod 60)"/>
  50. <xsl:variable name="sec" select="format-number((($num * 36000) mod 600) div 10, '0.0')"/>
  51. <xsl:value-of select="$deg"/>° <!--
  52. --><xsl:value-of select="$min"/>' <!--
  53. --><xsl:value-of select="$sec"/>"
  54. </xsl:when>
  55. <xsl:otherwise>?</xsl:otherwise>
  56. </xsl:choose>
  57. </xsl:template>
  58. <xsl:output
  59. method="html"
  60. doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"
  61. doctype-public="-//W3C//DTD XHTML 1.0 Strict//EN"/>
  62. <!-- http://stackoverflow.com/a/16328207 -->
  63. <xsl:key name="CategorY" match="a:entry/a:category" use="@term" />
  64. <xsl:template match="a:feed">
  65. <html xmlns="http://www.w3.org/1999/xhtml">
  66. <head>
  67. <meta content="text/html; charset=utf-8" http-equiv="content-type"/>
  68. <!-- https://developer.apple.com/library/IOS/documentation/AppleApplications/Reference/SafariWebContent/UsingtheViewport/UsingtheViewport.html#//apple_ref/doc/uid/TP40006509-SW26 -->
  69. <!-- http://maddesigns.de/meta-viewport-1817.html -->
  70. <!-- meta name="viewport" content="width=device-width"/ -->
  71. <!-- http://www.quirksmode.org/blog/archives/2013/10/initialscale1_m.html -->
  72. <meta name="viewport" content="width=device-width,initial-scale=1.0"/>
  73. <!-- meta name="viewport" content="width=400"/ -->
  74. <!-- http://lokeshdhakar.com/projects/lightbox2/#how-to-use -->
  75. <link href="assets/lightbox2/css/lightbox.min.css" rel="stylesheet" />
  76. <link href="assets/style.css" rel="stylesheet" type="text/css"/>
  77. <title>
  78. <xsl:value-of select="a:title"/>
  79. </title>
  80. <link href="photos.atom" rel="alternate" type="application/atom+xml"/>
  81. </head>
  82. <body id="photofeed">
  83. <h1><xsl:value-of select="a:title"/></h1>
  84. <ul id="photos">
  85. <xsl:for-each select="a:entry">
  86. <xsl:sort select="a:updated" order="descending"/>
  87. <li id="{substring-after(a:id, '#')}">
  88. <xsl:attribute name="class">
  89. <xsl:for-each select="a:category">cat_<xsl:value-of select="generate-id(key('CategorY',@term))"/><xsl:text> </xsl:text></xsl:for-each>
  90. </xsl:attribute>
  91. <xsl:variable name="time" select="substring(translate(a:updated,'T',' '), 1, 16)"/>
  92. <a href="{a:link[@rel='enclosure']/@href}" title="{a:updated} {normalize-space(a:title)}" data-lightbox="foo" data-title="{normalize-space(a:title)} | {$time}">
  93. <img alt="{normalize-space(a:summary)}" src="{a:link[@rel='previewimage']/@href}"/>
  94. </a>
  95. <span style="display:none">
  96. <span class="title"><xsl:value-of select="a:title"/></span><br class='br'/>
  97. <span class="time"><xsl:value-of select="$time"/></span><br class='br'/>
  98. <xsl:variable name="lat" select="substring-before(georss:point, ' ')"/>
  99. <xsl:variable name="lon" select="substring-after(georss:point, ' ')"/>
  100. gps: <a class="geo" title="{$lat},{$lon}" href="http://www.openstreetmap.org/?mlat={$lat}&amp;mlon={$lon}#map=13/{$lat}/{$lon}&amp;layers=C">
  101. <!-- xsl:value-of select="georss:point"/ -->
  102. <xsl:call-template name="degrees"><xsl:with-param name="num" select="$lat"/></xsl:call-template>
  103. <xsl:text> </xsl:text>
  104. <xsl:call-template name="degrees"><xsl:with-param name="num" select="$lon"/></xsl:call-template>
  105. </a><br class='br'/>
  106. <span class="categories">
  107. <xsl:for-each select="a:category">
  108. <a onclick="toggleCategory(this)" class="category cat_{generate-id(key('CategorY',@term))}"><xsl:value-of select="@label"/></a>,
  109. </xsl:for-each>
  110. .
  111. </span>
  112. </span>
  113. </li>
  114. </xsl:for-each>
  115. </ul>
  116. <p style="clear:both">
  117. <xsl:for-each select="a:entry/a:updated">
  118. <xsl:sort select="." order="ascending"/>
  119. <xsl:if test="position() = 1"><xsl:value-of select="substring(., 1, 10)"/></xsl:if>
  120. </xsl:for-each>
  121. -
  122. <xsl:for-each select="a:entry/a:updated">
  123. <xsl:sort select="." order="descending"/>
  124. <xsl:if test="position() = 1"><xsl:value-of select="substring(., 1, 10)"/></xsl:if>
  125. </xsl:for-each>,
  126. #<xsl:value-of select="count(a:entry)"/>
  127. </p>
  128. <div style="display:none">
  129. <h2 style="clear:left">Schlagworte</h2>
  130. <ul id="categories" class="categories">
  131. <!-- http://stackoverflow.com/a/16328207 -->
  132. <xsl:for-each select="a:entry/a:category[generate-id() = generate-id(key('CategorY',@term))]">
  133. <xsl:sort select="@label"/>
  134. <xsl:sort select="@term"/>
  135. <li id="{generate-id(key('CategorY',@term))}">
  136. <a onclick="toggleCategory(this)" class="category cat_{generate-id(key('CategorY',@term))}"><xsl:value-of select="@label"/></a><xsl:text> </xsl:text><xsl:value-of select="count(../../a:entry[a:category/@term = current()/@term])"/>
  137. </li>
  138. </xsl:for-each>
  139. </ul>
  140. </div>
  141. <!-- http://lokeshdhakar.com/projects/lightbox2/#how-to-use -->
  142. <script src="assets/lightbox2/js/lightbox-plus-jquery.min.js" type="text/javascript"></script>
  143. <script src="assets/script.js" type="text/javascript"></script>
  144. <p id="footer" style="clear:both">
  145. Powered by <a href="http://purl.mro.name/Photos2Atom">purl.mro.name/Photos2Atom</a>
  146. and <a rel="license" href="https://creativecommons.org/licenses/by/2.5/"><img alt=
  147. "Creative Commons License" src=
  148. "assets/by.svg" style="border:0;width:88px;height:31px"/></a>
  149. <span xmlns:dct="http://purl.org/dc/terms/" property="dct:title">lightbox2</span> by <a xmlns:cc=
  150. "http://creativecommons.org/ns#" href="http://lokeshdhakar.com/projects/lightbox2/" property=
  151. "cc:attributionName" rel="cc:attributionURL">Lokesh Dhakar</a> is licensed under a <a rel=
  152. "license" href="https://creativecommons.org/licenses/by/2.5/">Creative Commons Attribution 2.5 License</a>.
  153. <br class="br"/>
  154. <a title="Validate my Atom 1.0 feed" href="https://validator.w3.org/feed/check.cgi?url={a:link[@rel='self']/@href}">
  155. <img alt="Valid Atom 1.0" src="assets/valid-atom.png" style="border:0;width:88px;height:31px"/>
  156. </a><xsl:text> </xsl:text>
  157. <a href="https://validator.w3.org/check?uri=referer">
  158. <img alt="Valid XHTML 1.0 Strict" src="assets/valid-xhtml10-blue-v.svg" style="border:0;width:88px;height:31px"/>
  159. </a>
  160. <a href="https://jigsaw.w3.org/css-validator/check/referer?profile=css3&amp;usermedium=screen&amp;warning=2&amp;vextwarning=false&amp;lang=de">
  161. <img alt="CSS ist valide!" src="assets/valid-css-blue-v.svg" style="border:0;width:88px;height:31px"/>
  162. </a>
  163. <!-- https://i.creativecommons.org/l/by/2.5/88x31.png -->
  164. </p>
  165. </body>
  166. </html>
  167. </xsl:template>
  168. </xsl:stylesheet>