lastcraft.xslt 11KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302
  1. <?xml version="1.0"?>
  2. <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  3. <!-- $Id: lastcraft.xslt 1376 2006-11-02 01:21:38Z lastcraft $ -->
  4. <xsl:output method="html" indent="yes" />
  5. <xsl:preserve-space elements="*"/>
  6. <xsl:template match="/">
  7. <html>
  8. <xsl:call-template name="head"/>
  9. <xsl:call-template name="body"/>
  10. </html>
  11. </xsl:template>
  12. <xsl:template name="head">
  13. <head>
  14. <title><xsl:value-of select="//long_title"/></title>
  15. <link rel="stylesheet" type="text/css" href="styles/lastcraft.css" title="Last Craft styles" />
  16. <xsl:call-template name="ie_style_fixes"/>
  17. <link rel="Shortcut icon" href="images/lc.ico" />
  18. <xsl:call-template name="meta"/>
  19. </head>
  20. </xsl:template>
  21. <xsl:template name="ie_style_fixes">
  22. <style type="text/css">
  23. <![CDATA[
  24. <?php
  25. $is_ie = preg_match('/msie/i', $_SERVER['HTTP_USER_AGENT']) ||
  26. preg_match('/msie/i', $HTTP_SERVER_VARS['HTTP_USER_AGENT']);
  27. if ($is_ie) {
  28. print "div.menu_back {position: absolute}\n";
  29. print "div.iconic {position: absolute}\n";
  30. print "div.copyright {position: absolute}\n";
  31. print "ul {padding-left: 20px}\n";
  32. print "body {font-size: 80%}\n";
  33. print "div.menu {margin: 0px; font-size: 80%}\n";
  34. print "div.menu_back {padding: 0px}\n";
  35. print "div.card {margin: 0px; font-size: 80%}\n";
  36. print "div.card_back {padding: 0px}\n";
  37. }
  38. ?>
  39. ]]>
  40. </style>
  41. </xsl:template>
  42. <xsl:template name="meta">
  43. <meta name="author" content="Marcus Baker" />
  44. <meta name="description">
  45. <xsl:attribute name="content">
  46. <xsl:value-of select="normalize-space(/page/meta/description)"/>
  47. </xsl:attribute>
  48. </meta>
  49. <meta name="keywords">
  50. <xsl:attribute name="content">
  51. <xsl:value-of select="normalize-space(/page/meta/keywords)"/>
  52. </xsl:attribute>
  53. </meta>
  54. </xsl:template>
  55. <xsl:template name="body">
  56. <body background="images/graph_paper.png">
  57. <xsl:call-template name="logo"/>
  58. <xsl:call-template name="menu"/>
  59. <xsl:call-template name="masthead"/>
  60. <div class="content">
  61. <xsl:apply-templates select="//content/node()"/>
  62. </div>
  63. <xsl:call-template name="copyright"/>
  64. </body>
  65. </xsl:template>
  66. <xsl:template name="logo">
  67. <div class="iconic">
  68. <a class="lightly" href="http://www.lastcraft.com/">
  69. <img class="lightly" alt="LastCraft Home Page" src="images/logo.jpg"/>
  70. </a>
  71. </div>
  72. </xsl:template>
  73. <xsl:template name="menu">
  74. <div class="menu_back">
  75. <div class="menu">
  76. <xsl:variable name="map" select="document('site_map.xml')/page"/>
  77. <h2>
  78. <xsl:call-template name="menu_item">
  79. <xsl:with-param name="here" select="/page/@here"/>
  80. <xsl:with-param name="map" select="$map"/>
  81. </xsl:call-template>
  82. </h2>
  83. <xsl:call-template name="menu_layer">
  84. <xsl:with-param name="here" select="/page/@here"/>
  85. <xsl:with-param name="map" select="$map"/>
  86. </xsl:call-template>
  87. </div>
  88. </div>
  89. </xsl:template>
  90. <xsl:template name="find_here">
  91. <xsl:param name="here"/>
  92. <xsl:param name="map"/>
  93. <xsl:choose>
  94. <xsl:when test="$map/@title = $here">
  95. <xsl:value-of select="$here"/>
  96. </xsl:when>
  97. <xsl:when test="count($map/page) = 0"></xsl:when>
  98. <xsl:otherwise>
  99. <xsl:for-each select="$map/page">
  100. <xsl:call-template name="find_here">
  101. <xsl:with-param name="here" select="$here"/>
  102. <xsl:with-param name="map" select="."/>
  103. </xsl:call-template>
  104. </xsl:for-each>
  105. </xsl:otherwise>
  106. </xsl:choose>
  107. </xsl:template>
  108. <xsl:template name="menu_item">
  109. <xsl:param name="here"/>
  110. <xsl:param name="map"/>
  111. <xsl:choose>
  112. <xsl:when test="$map/@title = $here">
  113. <span class="chosen"><xsl:value-of select="$map/@title"/></span>
  114. </xsl:when>
  115. <xsl:otherwise>
  116. <a>
  117. <xsl:attribute name="href"><xsl:value-of select="$map/@file"/></xsl:attribute>
  118. <xsl:value-of select="$map/@title"/>
  119. </a>
  120. </xsl:otherwise>
  121. </xsl:choose>
  122. </xsl:template>
  123. <xsl:template name="menu_layer">
  124. <xsl:param name="here"/>
  125. <xsl:param name="map"/>
  126. <xsl:if test="$map/page">
  127. <ul>
  128. <xsl:for-each select="$map/page">
  129. <li>
  130. <xsl:call-template name="show_menu_entry">
  131. <xsl:with-param name="here" select="$here"/>
  132. <xsl:with-param name="map" select="."/>
  133. </xsl:call-template>
  134. </li>
  135. </xsl:for-each>
  136. </ul>
  137. </xsl:if>
  138. </xsl:template>
  139. <xsl:template name="show_menu_entry">
  140. <xsl:param name="here"/>
  141. <xsl:param name="map"/>
  142. <xsl:call-template name="menu_item">
  143. <xsl:with-param name="here" select="$here"/>
  144. <xsl:with-param name="map" select="$map"/>
  145. </xsl:call-template>
  146. <xsl:variable name="is_in">
  147. <xsl:call-template name="find_here">
  148. <xsl:with-param name="here" select="$here"/>
  149. <xsl:with-param name="map" select="$map"/>
  150. </xsl:call-template>
  151. </xsl:variable>
  152. <xsl:choose>
  153. <xsl:when test="$is_in = $here">
  154. <xsl:call-template name="menu_layer">
  155. <xsl:with-param name="here" select="$here"/>
  156. <xsl:with-param name="map" select="$map"/>
  157. </xsl:call-template>
  158. </xsl:when>
  159. <xsl:when test="$map/page">
  160. <br/>(<xsl:value-of select="count(page) + 1"/><xsl:text> pages)</xsl:text>
  161. </xsl:when>
  162. </xsl:choose>
  163. </xsl:template>
  164. <xsl:template name="masthead">
  165. <div class="card_back">
  166. <div class="card">
  167. <h1><xsl:value-of select="//page/@title"/></h1>
  168. <div class="in">
  169. <xsl:call-template name="internal_links"/>
  170. </div>
  171. <div class="out">
  172. <xsl:call-template name="external_links"/>
  173. </div>
  174. </div>
  175. </div>
  176. </xsl:template>
  177. <xsl:template name="internal_links">
  178. This page...
  179. <ul>
  180. <xsl:apply-templates select="//internal/link" mode="links"/>
  181. </ul>
  182. </xsl:template>
  183. <xsl:template name="external_links">
  184. Related...
  185. <ul>
  186. <xsl:apply-templates select="//external/link" mode="links"/>
  187. </ul>
  188. </xsl:template>
  189. <xsl:template name="copyright">
  190. <div class="copyright">
  191. Copyright<br/><a href="mailto:marcus@lastcraft.com">Marcus Baker</a> 2003
  192. </div>
  193. </xsl:template>
  194. <xsl:template match="php">
  195. <pre>
  196. <xsl:call-template name="preserve_strong">
  197. <xsl:with-param name="raw" select="."/>
  198. </xsl:call-template>
  199. </pre>
  200. </xsl:template>
  201. <xsl:template match="code">
  202. <span class="new_code">
  203. <xsl:apply-templates/>
  204. </span>
  205. </xsl:template>
  206. <xsl:template match="sh">
  207. <pre class="shell">
  208. <xsl:call-template name="preserve_strong">
  209. <xsl:with-param name="raw" select="."/>
  210. </xsl:call-template>
  211. </pre>
  212. </xsl:template>
  213. <xsl:template match="file">
  214. <pre class="file">
  215. <xsl:apply-templates/>
  216. </pre>
  217. </xsl:template>
  218. <xsl:template match="section">
  219. <p>
  220. <a class="target">
  221. <xsl:attribute name="name"><xsl:value-of select="@name"/></xsl:attribute>
  222. <h2><xsl:value-of select="@title"/></h2>
  223. </a>
  224. </p>
  225. <xsl:apply-templates/>
  226. </xsl:template>
  227. <xsl:template match="introduction">
  228. <xsl:apply-templates/>
  229. </xsl:template>
  230. <xsl:template match="news">
  231. <p style="margin-right: 10%; margin-left: 10%;">
  232. <span style="color: red;">News:</span>
  233. <xsl:apply-templates/>
  234. </p>
  235. </xsl:template>
  236. <xsl:template match="a">
  237. <xsl:copy>
  238. <xsl:for-each select="@class|@name|@href">
  239. <xsl:attribute name="{local-name(.)}"><xsl:value-of select="."/></xsl:attribute>
  240. </xsl:for-each>
  241. <xsl:for-each select="@local">
  242. <xsl:attribute name="href">
  243. <xsl:value-of select="."/><xsl:text>.php</xsl:text>
  244. </xsl:attribute>
  245. </xsl:for-each>
  246. <xsl:apply-templates/>
  247. </xsl:copy>
  248. </xsl:template>
  249. <xsl:template match="*">
  250. <xsl:copy>
  251. <xsl:for-each select="@*">
  252. <xsl:attribute name="{local-name(.)}"><xsl:value-of select="."/></xsl:attribute>
  253. </xsl:for-each>
  254. <xsl:apply-templates/>
  255. </xsl:copy>
  256. </xsl:template>
  257. <xsl:template match="*" mode="links">
  258. <li><xsl:apply-templates/></li>
  259. </xsl:template>
  260. <xsl:template name="preserve_strong">
  261. <xsl:param name="raw"/>
  262. <xsl:choose>
  263. <xsl:when test="contains($raw, '&lt;strong&gt;') and contains($raw, '&lt;/strong&gt;')">
  264. <xsl:value-of select="substring-before($raw, '&lt;strong&gt;')"/>
  265. <strong>
  266. <xsl:value-of select="substring-before(substring-after($raw, '&lt;strong&gt;'), '&lt;/strong&gt;')"/>
  267. </strong>
  268. <xsl:call-template name="preserve_strong">
  269. <xsl:with-param name="raw" select="substring-after($raw, '&lt;/strong&gt;')"/>
  270. </xsl:call-template>
  271. </xsl:when>
  272. <xsl:otherwise><xsl:value-of select="$raw"/></xsl:otherwise>
  273. </xsl:choose>
  274. </xsl:template>
  275. </xsl:stylesheet>