util.xsl 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!--
  3. _ _ ____ _
  4. _| || |_/ ___| ___ _ __ _ __ ___ | |
  5. |_ .. _\___ \ / _ \ '_ \| '_ \ / _ \| |
  6. |_ _|___) | __/ |_) | |_) | (_) |_|
  7. |_||_| |____/ \___| .__/| .__/ \___/(_)
  8. |_| |_|
  9. Personal Social Web.
  10. Copyright (C) The #Seppo contributors. All rights reserved.
  11. This program is free software: you can redistribute it and/or modify
  12. it under the terms of the GNU General Public License as published by
  13. the Free Software Foundation, either version 3 of the License, or
  14. (at your option) any later version.
  15. This program is distributed in the hope that it will be useful,
  16. but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. GNU General Public License for more details.
  19. You should have received a copy of the GNU General Public License
  20. along with this program. If not, see <http://www.gnu.org/licenses/>.
  21. https://w3.org/TR/xslt-10
  22. https://w3.org/TR/xpath-10
  23. -->
  24. <xsl:stylesheet
  25. xmlns="http://www.w3.org/1999/xhtml"
  26. xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
  27. xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  28. exclude-result-prefixes="rdf"
  29. xmlns:math="http://exslt.org/math"
  30. extension-element-prefixes="math"
  31. version="1.0">
  32. <xsl:variable name="nbsp">&#xa0;</xsl:variable>
  33. <!-- replace linefeeds with <br> tags -->
  34. <xsl:template name="linefeed2br">
  35. <xsl:param name="string" select="''"/>
  36. <xsl:param name="pattern" select="'&#10;'"/>
  37. <xsl:choose>
  38. <xsl:when test="contains($string, $pattern)">
  39. <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>
  40. <xsl:call-template name="linefeed2br">
  41. <xsl:with-param name="string" select="substring-after($string, $pattern)"/>
  42. <xsl:with-param name="pattern" select="$pattern"/>
  43. </xsl:call-template>
  44. </xsl:when>
  45. <xsl:otherwise>
  46. <xsl:value-of select="$string"/>
  47. </xsl:otherwise>
  48. </xsl:choose>
  49. </xsl:template>
  50. <xsl:template name="calculate-day-of-the-week">
  51. <!-- https://www.oreilly.com/library/view/xslt-cookbook/0596003722/ch03s02.html -->
  52. <xsl:param name="date-time"/>
  53. <xsl:param name="date" select="substring-before($date-time,'T')"/>
  54. <xsl:param name="year" select="substring-before($date,'-')"/>
  55. <xsl:param name="month" select="substring-before(substring-after($date,'-'),'-')"/>
  56. <xsl:param name="day" select="substring-after(substring-after($date,'-'),'-')"/>
  57. <xsl:variable name="a" select="floor((14 - $month) div 12)"/>
  58. <xsl:variable name="y" select="$year - $a"/>
  59. <xsl:variable name="m" select="$month + 12 * $a - 2"/>
  60. <xsl:value-of select="($day + $y + floor($y div 4) - floor($y div 100) + floor($y div 400) + floor((31 * $m) div 12)) mod 7"/>
  61. </xsl:template>
  62. <xsl:template name="human_time">
  63. <xsl:param name="time">-</xsl:param>
  64. <xsl:variable name="wday">
  65. <xsl:call-template name="calculate-day-of-the-week">
  66. <xsl:with-param name="date-time" select="$time"/>
  67. </xsl:call-template>
  68. </xsl:variable>
  69. <xsl:choose>
  70. <xsl:when test="0 = $wday">Sun</xsl:when>
  71. <xsl:when test="1 = $wday">Mon</xsl:when>
  72. <xsl:when test="2 = $wday">Tue</xsl:when>
  73. <xsl:when test="3 = $wday">Wed</xsl:when>
  74. <xsl:when test="4 = $wday">Thu</xsl:when>
  75. <xsl:when test="5 = $wday">Fri</xsl:when>
  76. <xsl:when test="6 = $wday">Sat</xsl:when>
  77. <xsl:otherwise>?</xsl:otherwise>
  78. </xsl:choose>
  79. <xsl:text>, </xsl:text>
  80. <xsl:value-of select="substring($time, 9, 2)"/><xsl:text>. </xsl:text>
  81. <xsl:variable name="month" select="substring($time, 6, 2)"/>
  82. <xsl:choose>
  83. <xsl:when test="'01' = $month">Jan</xsl:when>
  84. <xsl:when test="'02' = $month">Feb</xsl:when>
  85. <xsl:when test="'03' = $month">Mar</xsl:when>
  86. <xsl:when test="'04' = $month">Apr</xsl:when>
  87. <xsl:when test="'05' = $month">May</xsl:when>
  88. <xsl:when test="'06' = $month">Jun</xsl:when>
  89. <xsl:when test="'07' = $month">Jul</xsl:when>
  90. <xsl:when test="'08' = $month">Aug</xsl:when>
  91. <xsl:when test="'09' = $month">Sep</xsl:when>
  92. <xsl:when test="'10' = $month">Oct</xsl:when>
  93. <xsl:when test="'11' = $month">Nov</xsl:when>
  94. <xsl:when test="'12' = $month">Dec</xsl:when>
  95. <xsl:otherwise>?</xsl:otherwise>
  96. </xsl:choose><xsl:text> </xsl:text>
  97. <xsl:value-of select="substring($time, 1, 4)"/><xsl:text> </xsl:text>
  98. <xsl:value-of select="substring($time, 12, 5)"/><!-- xsl:text> Uhr</xsl:text -->
  99. </xsl:template>
  100. <xsl:template name="degrees">
  101. <xsl:param name="num" select="0"/>
  102. <xsl:choose>
  103. <xsl:when test="$num &lt; 0">-<xsl:call-template name="degrees"><xsl:with-param name="num" select="-$num"/></xsl:call-template></xsl:when>
  104. <xsl:when test="$num &gt;= 0">
  105. <xsl:variable name="deg" select="floor($num)"/>
  106. <xsl:variable name="min" select="floor(($num * 60) mod 60)"/>
  107. <xsl:variable name="sec" select="format-number((($num * 36000) mod 600) div 10, '0.0')"/>
  108. <xsl:value-of select="$deg"/>° <!--
  109. --><xsl:value-of select="$min"/>' <!--
  110. --><xsl:value-of select="$sec"/>"
  111. </xsl:when>
  112. <xsl:otherwise>?</xsl:otherwise>
  113. </xsl:choose>
  114. </xsl:template>
  115. </xsl:stylesheet>