styles/tm.xsl
author insilmaril
Mon, 19 Feb 2007 12:01:52 +0000
changeset 428 9ae68208e2ff
parent 37 df767ed748f3
permissions -rw-r--r--
1.8.67 Bugfixes
     1 <?xml version="1.0" encoding="iso-8859-1" standalone="yes"?>
     2 <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:exsl="http://exslt.org/common" extension-element-prefixes="exsl" version="1.0">
     3 
     4 <xsl:template name="getTopicName">
     5 	<xsl:param name="id"/>
     6 	<xsl:variable name="searching" select="$topics[@id=$id]" />
     7 	<xsl:variable name="get"><xsl:value-of select="$searching/baseName/baseNameString" /><xsl:value-of select="$searching/@name" /></xsl:variable>
     8 	<xsl:if test="string( $get )"><xsl:value-of select="$get" /></xsl:if>
     9 	<xsl:if test="not(string( $get ))"><span class="notFound"><xsl:value-of select="$id" /> not found.</span></xsl:if>
    10 </xsl:template>
    11 	
    12 <xsl:template name="getParent">
    13 	<xsl:param name="currentID"/>
    14 	<xsl:call-template name="getAllAssocID">
    15 		<xsl:with-param name="filter" select="'#group-subgroup'" />
    16 		<xsl:with-param name="role" select="'#parent'" />
    17 		<xsl:with-param name="currentID" select="$currentID" />
    18 	</xsl:call-template>
    19 </xsl:template>
    20 
    21 <xsl:template name="getChild">
    22 	<xsl:param name="currentID"/>
    23 	<xsl:call-template name="getAllAssocID">
    24 		<xsl:with-param name="filter" select="'#group-subgroup'" />
    25 		<xsl:with-param name="role" select="'#child'" />
    26 		<xsl:with-param name="currentID" select="$currentID" />
    27 	</xsl:call-template>
    28 </xsl:template>
    29 
    30 <xsl:template name="getAllAssocID">
    31 	<xsl:param name="filter"/>
    32 	<xsl:param name="role"/>
    33 	<xsl:param name="currentID"/>
    34 	
    35 	<xsl:variable name="theseOnes" select="$associations[instanceOf/topicRef/@xlink:href=$filter][member/topicRef/@xlink:href=concat('#',$currentID)]" />
    36 	<xsl:variable name="fiddle" select="$theseOnes/member/topicRef[not(@xlink:href=concat('#',$currentID))][parent::*/roleSpec/topicRef/@xlink:href=$role]" />
    37 
    38 	<xsl:value-of select="substring-after($fiddle[1]/@xlink:href, '#')" />
    39 	
    40 </xsl:template>
    41 
    42 <xsl:template name="getAllAssoc">
    43 	<xsl:param name="filter"/>
    44 	<xsl:param name="role"/>
    45 	<xsl:param name="style" select="'default'" />
    46 	<xsl:param name="title"/>
    47 	<xsl:param name="box"/>
    48 	<xsl:param name="without"/>
    49 	<xsl:param name="currentID"/>
    50 	<xsl:param name="againstID"/>
    51 	
    52 	<xsl:variable name="theseOnes" select="$associations[instanceOf/topicRef/@xlink:href=$filter][member/topicRef/@xlink:href=concat('#',$currentID)]" />
    53 
    54  	<xsl:variable name="found"><xsl:choose> 
    55 			<xsl:when test="$style = 'sections'">
    56 				<table border="0" cellspacing="0" cellpadding="0" class="sections"><tr>
    57 				<xsl:for-each select="$theseOnes/member/topicRef[@xlink:href!=concat('#',$currentID)][parent::*/roleSpec/topicRef/@xlink:href=$role]"> 
    58 					<xsl:variable name="thisOne" select="substring-after(@xlink:href, '#')" />
    59 					<xsl:variable name="cat" select="concat('#',$currentID)" />
    60 					<td valign="top" class="{$style}Menu">
    61 						<a href="{$pre-link}{$thisOne}{$post-link}" class="{$style}MenuLink"><xsl:call-template name="getTopicName"><xsl:with-param name="id" select="$thisOne" /></xsl:call-template></a>
    62 						<div class="{$style}MenuContent"><xsl:call-template name="getClue"><xsl:with-param name="currentID" select="$thisOne" /></xsl:call-template></div>
    63 					</td>
    64 		 		</xsl:for-each>
    65 				</tr></table>
    66 			</xsl:when>
    67 			<xsl:when test="$style = 'news'">
    68 				<xsl:for-each select="$theseOnes/member/topicRef[@xlink:href!=concat('#',$currentID)][parent::*/roleSpec/topicRef/@xlink:href=$role]"> 
    69 					<xsl:variable name="thisOne" select="substring-after(@xlink:href, '#')" />
    70 					<xsl:variable name="cat" select="concat('#',$currentID)" />
    71 					<div class="{$style}Menu">
    72 						<a href="{$pre-link}{$thisOne}{$post-link}" class="{$style}MenuLink">
    73 							<xsl:call-template name="getTopicName"><xsl:with-param name="id" select="$thisOne" /></xsl:call-template> : 
    74 							<xsl:call-template name="getClue"><xsl:with-param name="currentID" select="$thisOne" /><xsl:with-param name="style" select="'news'" /></xsl:call-template>
    75 						</a>
    76 					</div>
    77 		 		</xsl:for-each>
    78 			</xsl:when>
    79 			<xsl:when test="$style = 'smallnews'">
    80 				<xsl:for-each select="$theseOnes/member/topicRef[@xlink:href!=concat('#',$currentID)][parent::*/roleSpec/topicRef/@xlink:href=$role]"> 
    81 					<xsl:variable name="thisOne" select="substring-after(@xlink:href, '#')" />
    82 					<xsl:variable name="cat" select="concat('#',$currentID)" />
    83 					<div class="{$style}Menu">
    84 						<a href="{$pre-link}{$thisOne}{$post-link}" class="{$style}MenuLink">
    85 							<xsl:call-template name="getTopicName"><xsl:with-param name="id" select="$thisOne" /></xsl:call-template> : 
    86 							 <xsl:call-template name="getShort"><xsl:with-param name="currentID" select="$thisOne" /></xsl:call-template>
    87 						</a>
    88 					</div>
    89 		 		</xsl:for-each>
    90 			</xsl:when>
    91 			<xsl:otherwise>
    92 			
    93 				<xsl:variable name="allThese" select="$theseOnes/member/topicRef[@xlink:href!=concat('#',$currentID)][parent::*/roleSpec/topicRef/@xlink:href=$role]" />
    94 				<xsl:for-each select="$allThese"> 
    95 				
    96 				<xsl:variable name="thisOne" select="substring-after(@xlink:href, '#')" />
    97 					<xsl:variable name="cat" select="concat('#',$currentID)" />
    98 						<xsl:choose> 
    99 							<xsl:when test="$style = 'right' or $style = 'left' or $style = 'full' or $style = 'tree'">
   100 								<xsl:choose>
   101 									<xsl:when test="$thisOne = $againstID">
   102 										<div class="{$style}MenuSelected"><a href="{$pre-link}{$thisOne}{$post-link}"><xsl:call-template name="getTopicName"><xsl:with-param name="id" select="$thisOne" /></xsl:call-template></a> </div>
   103 									</xsl:when>
   104 									<xsl:otherwise>
   105 										<div class="{$style}Menu"><a href="{$pre-link}{$thisOne}{$post-link}"><xsl:call-template name="getTopicName"><xsl:with-param name="id" select="$thisOne" /></xsl:call-template></a> </div>
   106 									</xsl:otherwise>
   107 								</xsl:choose>
   108 							</xsl:when>
   109 							<xsl:when test="$style = 'banner'">
   110 								<xsl:choose>
   111 									<xsl:when test="$thisOne = $againstID">
   112 										<td class="{$style}MenuSelected"><a href="{$pre-link}{$thisOne}{$post-link}"><xsl:call-template name="getTopicName"><xsl:with-param name="id" select="$thisOne" /></xsl:call-template></a> </td>
   113 									</xsl:when>
   114 									<xsl:otherwise>
   115 										<td class="{$style}Menu"><a href="{$pre-link}{$thisOne}{$post-link}"><xsl:call-template name="getTopicName"><xsl:with-param name="id" select="$thisOne" /></xsl:call-template></a> </td>
   116 									</xsl:otherwise>
   117 								</xsl:choose>
   118 							</xsl:when>
   119 							<xsl:otherwise>
   120 								<xsl:if test="position() != 1"> / </xsl:if>
   121 								<a href="{$pre-link}{$thisOne}{$post-link}"><xsl:call-template name="getTopicName"><xsl:with-param name="id" select="$thisOne" /></xsl:call-template> </a>
   122 							</xsl:otherwise>
   123 						</xsl:choose>
   124 		 		</xsl:for-each>
   125 			</xsl:otherwise>
   126 		</xsl:choose>
   127 	</xsl:variable>
   128 	<xsl:if test="string($found)">
   129 		<xsl:choose>
   130 			<xsl:when test="string($box) and $style != 'news' and $style != 'right' and $style != 'left' and $style != 'full' and $style = 'tree' and $style = 'banner'">
   131 				<table class="{$box}">
   132 				<tr>
   133 					<xsl:if test="string($title)"><td class="{$box}Title"><xsl:value-of select="$title" /></td></xsl:if>
   134 					<td class="{$box}Content"><xsl:copy-of select="$found" /></td>
   135 				</tr>
   136 				</table>
   137 			</xsl:when>
   138 			<xsl:otherwise>
   139 				<xsl:copy-of select="$found" />
   140 			</xsl:otherwise>
   141 		</xsl:choose>
   142 	</xsl:if>
   143 </xsl:template>
   144 
   145 <xsl:template name="getAllAssocTwo">
   146 	<xsl:param name="filter"/>
   147 	<xsl:param name="role"/>
   148 	<xsl:param name="type"/>
   149 	<xsl:param name="style" select="'default'" />
   150 	<xsl:param name="title"/>
   151 	<xsl:param name="box"/>
   152 	<xsl:param name="without"/>
   153 	<xsl:param name="currentID"/>
   154 	<xsl:param name="againstID"/>
   155 	<xsl:variable name="theseOnes" select="$associations[instanceOf/topicRef/@xlink:href=$filter][member/topicRef/@xlink:href=concat('#',$currentID)]" />
   156 	<xsl:variable name="allThese" select="$theseOnes/member/topicRef[@xlink:href!=concat('#',$currentID)][parent::*/roleSpec/topicRef/@xlink:href=$role]" />
   157 	<xsl:variable name="w" select="substring-after($type, '#')" />
   158 	<xsl:variable name="all" select="$topics[starts-with(@id, concat($w, '-'))]" />
   159 	<xsl:variable name="found">
   160 		<xsl:for-each select="$all"> 
   161 			<xsl:variable name="this" select="@id" />
   162 			<xsl:variable name="c" select="count( $allThese[substring-after(@xlink:href, '#')=$this])" />
   163 			<xsl:if test="$c &gt; 0">
   164 				<xsl:variable name="single" select="$this[1]" />
   165 				<a href="{$pre-link}{$single}{$post-link}" class="foundLink"><xsl:call-template name="getTopicName"><xsl:with-param name="id" select="$single" /></xsl:call-template></a>
   166 			</xsl:if>
   167 		</xsl:for-each>
   168 	</xsl:variable>
   169 	<xsl:if test="string($found)"><xsl:copy-of select="$found" /></xsl:if>
   170 </xsl:template>
   171 
   172 <xsl:template name="drawNextLevel">	
   173 	<xsl:param name="currentID"/>
   174 	<xsl:param name="againstID"/>
   175 	<xsl:param name="currentType"/>
   176 	<xsl:param name="currentRole"/>
   177 	<xsl:param name="style"/>
   178 	<xsl:call-template name="getAllAssoc">
   179 		<xsl:with-param name="currentID" select="$currentID" />
   180 		<xsl:with-param name="againstID" select="$againstID" />
   181 		<xsl:with-param name="filter" select="'#group-subgroup'" />
   182 		<xsl:with-param name="role" select="$currentRole" />
   183 		<xsl:with-param name="box" select="'box'" />
   184 		<xsl:with-param name="style" select="$style" />
   185 	</xsl:call-template>
   186 </xsl:template>
   187 
   188 <xsl:template name="drawRelated">
   189 	<xsl:param name="currentID"/>
   190 	<xsl:param name="currentType"/>
   191 	<xsl:param name="currentRole"/>
   192 	<xsl:param name="style" select="'box'" />
   193 	<xsl:call-template name="getAll">
   194 		<xsl:with-param name="ThisThat" select="'#this'" />
   195 		<xsl:with-param name="role" select="$currentRole" />
   196 		<xsl:with-param name="box" select="$style" />
   197 		<xsl:with-param name="currentID" select="$currentID" />
   198 	</xsl:call-template>
   199 	<xsl:call-template name="getAll">
   200 		<xsl:with-param name="ThisThat" select="'#that'" />
   201 		<xsl:with-param name="role" select="$currentRole" />
   202 		<xsl:with-param name="box" select="$style" />
   203 		<xsl:with-param name="currentID" select="$currentID" />
   204 	</xsl:call-template>
   205 </xsl:template> 	
   206 
   207 <xsl:template name="getAll">
   208 	<xsl:param name="ThisThat"/>
   209 	<xsl:param name="filter"/>
   210 	<xsl:param name="title"/>
   211 	<xsl:param name="role"/>
   212 	<xsl:param name="box"/>
   213 	<xsl:param name="without"/>
   214 	<xsl:param name="currentID"/>
   215 	<xsl:variable name="allRelations" select="$topics[starts-with(@id, 'relation-')]" />
   216 	<xsl:variable name="allAssociations" select="$associations[member/topicRef/@xlink:href=concat('#',$currentID)]" />
   217 	<xsl:for-each select="$allRelations">
   218 		<xsl:variable name="relID" select="concat('#', @id)" />
   219 		<xsl:variable name="ThisThatRole"><xsl:choose><xsl:when test="$ThisThat = '#that'">#child</xsl:when><xsl:otherwise>#parent</xsl:otherwise></xsl:choose></xsl:variable>
   220 		<xsl:variable name="thisName"><xsl:value-of select="baseName[scope/topicRef/@xlink:href=$ThisThat]/baseNameString" /></xsl:variable>
   221 		<xsl:variable name="found">
   222 			<xsl:for-each select="$allAssociations">
   223 				<xsl:variable name="assocInstance" select="instanceOf/topicRef/@xlink:href" />
   224 				<xsl:variable name="assocHref" select="member[roleSpec/topicRef/@xlink:href=$ThisThatRole]/topicRef/@xlink:href" />
   225 				<xsl:variable name="thisID" select="substring-after($assocHref, '#')" />
   226 				<xsl:if test="$relID = $assocInstance and $thisID != $currentID">			
   227 					<span class="{$box}Element"><a href="{$pre-link}{$thisID}{$post-link}"><xsl:call-template name="getTopicName"><xsl:with-param name="id" select="$thisID" /></xsl:call-template></a></span>
   228 				</xsl:if>
   229 			</xsl:for-each>
   230 		</xsl:variable>
   231 		<xsl:if test="string($found) and string($thisName)">
   232 			<xsl:call-template name="drawRelationsBox">
   233 				<xsl:with-param name="style" select="$box" />
   234 				<xsl:with-param name="title" select="$thisName" />
   235 				<xsl:with-param name="content" select="$found" />
   236 			</xsl:call-template>
   237 		</xsl:if>
   238 	</xsl:for-each>	
   239 </xsl:template>
   240 
   241 <xsl:template name="getAllBlogs">
   242 	<xsl:param name="currentID"/>
   243 	<xsl:param name="notraverse"/>
   244 	
   245 	<xsl:variable name="parentID">
   246 		<xsl:call-template name="getParent">
   247 			<xsl:with-param name="currentID" select="$currentID" />
   248 		</xsl:call-template>
   249 	</xsl:variable>
   250 	<xsl:choose>
   251 		<xsl:when test="string($notraverse)">
   252 			<xsl:variable name="theseOnes" select="$topics[instanceOf/topicRef/@xlink:href='#blog']" />
   253 			<xsl:variable name="assoc" select="$associations[instanceOf/topicRef/@xlink:href='#group-subgroup'][member/topicRef/@xlink:href=concat('#',$currentID)]/member[roleSpec/topicRef/@xlink:href='#child']/topicRef" />
   254 			<div class="doc">
   255 				<xsl:for-each select="$theseOnes">
   256 					<xsl:variable name="ct" select="." />
   257 					<xsl:for-each select="$assoc">
   258 						<xsl:variable name="ca" select="." />
   259 						<xsl:variable name="t" select="substring-after($ca/@xlink:href, '#')" />
   260 						<xsl:if test="$t = $ct/@id">
   261 							<xsl:variable name="currentDate" select="$ct/occurrence[instanceOf/topicRef/@xlink:href='#blog-date']/resourceData" />
   262 							<div class="blogDate"><xsl:value-of select="$currentDate" /></div>
   263 							<xsl:call-template name="displayBlogItem">
   264 								<xsl:with-param name="item" select="$ct" />
   265 							</xsl:call-template>
   266 						</xsl:if>
   267 					</xsl:for-each>
   268 				</xsl:for-each>
   269 			</div>
   270 		</xsl:when>
   271 		<xsl:otherwise>
   272 			<xsl:variable name="items" select="$topics[instanceOf/topicRef/@xlink:href='#blog']" />
   273 			<xsl:call-template name="traverseBlog">
   274 				<xsl:with-param name="items" select="$items[position() &lt; 6]" />
   275 				<xsl:with-param name="currentNo" select="'1'" />
   276 			</xsl:call-template>
   277 		</xsl:otherwise>
   278 	</xsl:choose>
   279 
   280 </xsl:template>
   281 
   282 <xsl:template name="traverseBlog">
   283 	<xsl:param name="items" />
   284 	<xsl:param name="currentNo" />
   285 	<xsl:param name="previousDate" />
   286 	
   287 	<xsl:variable name="item" select="$items[position() = $currentNo]" />
   288 
   289 	<xsl:variable name="currentDate" select="$item/occurrence[instanceOf/topicRef/@xlink:href='#blog-date']/resourceData" />
   290 
   291 	<xsl:if test="string($currentDate)">
   292 	
   293 		<xsl:if test="string($previousDate) = string($currentDate)">
   294 			<div class="blogEnd"> </div>
   295 		</xsl:if>
   296 		
   297 		<xsl:if test="$previousDate != $currentDate">
   298 			<div class="blogDate"><xsl:value-of select="$currentDate" /></div>
   299 		</xsl:if>
   300 		
   301 		<xsl:call-template name="displayBlogItem">
   302 			<xsl:with-param name="item" select="$item" />
   303 		</xsl:call-template>
   304 		
   305 		<xsl:if test="string($items[position() = $currentNo+1])">
   306 			<xsl:call-template name="traverseBlog">
   307 				<xsl:with-param name="items" select="$items" />
   308 				<xsl:with-param name="currentNo" select="$currentNo + 1" />
   309 				<xsl:with-param name="previousDate" select="$currentDate" />
   310 			</xsl:call-template>
   311 		</xsl:if>
   312 	
   313 	</xsl:if>
   314 	
   315 </xsl:template>
   316 
   317 <xsl:template name="displayBlogItem">
   318 	<xsl:param name="item" />
   319 	
   320 	<xsl:variable name="currentHeader" select="$item/baseName/baseNameString" />
   321 	<xsl:variable name="currentDate" select="$item/occurrence[instanceOf/topicRef/@xlink:href='#blog-date']/resourceData" />
   322 	<xsl:variable name="currentLink" select="$item/occurrence[instanceOf/topicRef/@xlink:href='#blog-link']/resourceData" />
   323 	<xsl:variable name="currentShort" select="$item/occurrence[instanceOf/topicRef/@xlink:href='#blog-short']/resourceData" />
   324 	
   325 	<div class="blogItem">
   326 		<xsl:if test="string($currentHeader)"><div class="blogHeader"><xsl:value-of select="$currentHeader" /></div></xsl:if>
   327 		
   328 		<xsl:variable name="fileName">../content/<xsl:value-of select="$item/@id" />.xml</xsl:variable>
   329 		<xsl:variable name="this" select="document($fileName)/div/*" />
   330 		<xsl:apply-templates select="$this"><xsl:with-param name="currentID" select="$item/@id" /></xsl:apply-templates>
   331 		
   332 		<xsl:if test="string($currentLink)"><div class="blogLinkBox">Read the full story at &lt; <a href="{$currentLink}"><xsl:value-of select="$currentHeader" /></a> &gt;</div></xsl:if>
   333 
   334 		<xsl:variable name="theseOnes" select="$associations[instanceOf/topicRef/@xlink:href='#group-subgroup'][member/topicRef/@xlink:href=concat('#',$item/@id)]/member[roleSpec/topicRef/@xlink:href='#parent']" />
   335 
   336 		<span class="blogLinks"><a href="{$item/@id}.html" class="blogLink">Permalink</a>added <strong><xsl:value-of select="$currentDate" /></strong>.</span> 
   337 		
   338 		<xsl:if test="count($theseOnes) &gt; 0">
   339 			<span class="blogLinks">
   340 				Catalogued under:
   341 				<xsl:for-each select="$theseOnes">
   342 					<xsl:variable name="chug" select="substring-after(topicRef/@xlink:href, '#')" />
   343 					<a href="{$pre-link}{$chug}{$post-link}" class="blogLink"><xsl:call-template name="getTopicName"><xsl:with-param name="id" select="$chug" /></xsl:call-template> </a>
   344 				</xsl:for-each>
   345 	 		</span>
   346 		</xsl:if>
   347 		
   348 	</div>
   349 	
   350 </xsl:template>
   351 
   352 
   353 </xsl:stylesheet>