styles/cm.xsl
author insilmaril
Wed, 20 Jun 2007 10:51:45 +0000
changeset 517 b525fdd445c4
parent 37 df767ed748f3
permissions -rw-r--r--
scripted exports (continued)
     1 <?xml version="1.0" encoding="iso-8859-1" standalone="yes"?>
     2 <xsl:stylesheet 
     3 	xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
     4 	xmlns:exsl="http://exslt.org/common"
     5 	extension-element-prefixes="exsl" version="1.0">
     6 	
     7 <xsl:variable name="controlCharacter" select="'¤'" />
     8 <xsl:variable name="crlf" select="'&#10;'" />
     9 <!-- <xsl:variable name="wikistyle" select="false()" /> -->
    10 
    11 <xsl:variable name="supportMenu" select="'true'" />
    12 <xsl:variable name="supportShowme" select="'true'" />
    13 <xsl:variable name="supportSource" select="'true'" />
    14 <xsl:variable name="supportImage" select="'true'" />
    15 
    16 <xsl:template name="findNext">
    17 	<xsl:param name="content" />
    18 	<xsl:variable name="escaped" select="substring-after( $content, '\{' )" />
    19 	<xsl:variable name="item-start" select="substring-after( $content, '{' )" />
    20 	<xsl:variable name="item-end" select="substring-before( $item-start, '}' )" />
    21 	<xsl:if test="normalize-space($escaped) != normalize-space($item-start)">
    22 		<xsl:copy-of select="normalize-space($item-end)" />
    23 	</xsl:if>
    24 </xsl:template>
    25 
    26 <xsl:template name="findNextTag">
    27 	<xsl:param name="content" />
    28 	<xsl:variable name="item-start" select="substring-after( $content, '|' )" />
    29 	<xsl:variable name="item-end" select="substring-before( $item-start, '|' )" />
    30 	<xsl:variable name="name-start" select="substring-after( $item-start, '(' )" />
    31 	<xsl:variable name="name-end" select="substring-before( $name-start, ')' )" />
    32 	<!-- <xsl:copy-of select="normalize-space($item-end)" /> -->
    33 	<xsl:variable name="w" select="substring-after( $item-end, ') ')" />
    34 	<xsl:if test="string($w)">
    35 		<xsl:element name="{$w}">
    36 			<xsl:value-of select="$name-end" />
    37 		</xsl:element>
    38 	</xsl:if>
    39 </xsl:template>
    40 
    41 <xsl:template name="lastCall">
    42 	<xsl:param name="content" />
    43 
    44 	<xsl:variable name="inTheBeginning"   select="substring-before( $content, '|' )" />
    45 	<xsl:variable name="markup-start"     select="substring-after( $content, '|' )" />
    46 	<xsl:variable name="markup-end"       select="substring-before( $markup-start, '|' )" />
    47 	<xsl:variable name="markup-after"     select="substring-after( $markup-start, concat( $markup-end, '|') )" />
    48 	
    49 	<xsl:variable name="cmd"              select="substring-before( $markup-end, ';' )" />
    50 	
    51 	<xsl:copy-of select="$inTheBeginning" />
    52 	
    53 	<xsl:choose>
    54 		<xsl:when test="string($markup-end)">
    55 			<xsl:choose>
    56 				<xsl:when test="starts-with( $markup-end, '!' )">
    57 					<span class="note"><xsl:copy-of select="substring-after( $markup-end, '!')" /></span>
    58 				</xsl:when>
    59 				<xsl:when test="starts-with( $markup-end, '/' )">
    60 					<em><xsl:copy-of select="substring-after( $markup-end, '/')" /></em>
    61 				</xsl:when>
    62 				<xsl:when test="starts-with( $markup-end, '*' )">
    63 					<pre><xsl:copy-of select="substring-after( $markup-end, '*')" /></pre>
    64 				</xsl:when>
    65 				<xsl:otherwise>
    66 					<strong><xsl:copy-of select="$markup-end" /></strong>
    67 				</xsl:otherwise>
    68 			</xsl:choose>
    69 			<xsl:call-template name="lastCall">
    70 				<xsl:with-param name="content" select="$markup-after" />
    71 			</xsl:call-template>
    72 			<!-- [<xsl:copy-of select="$markup-after" />] -->
    73 		</xsl:when>
    74 		<xsl:otherwise>
    75 			<xsl:copy-of select="$content" />
    76 		</xsl:otherwise>
    77 	</xsl:choose>
    78 	
    79 </xsl:template>
    80 
    81 <xsl:template name="replace-tags">
    82 	<xsl:param name="content" />
    83 	<xsl:param name="currentID" />
    84 	<xsl:variable name="topic"><xsl:call-template name="findNext"><xsl:with-param name="content" select="$content" /></xsl:call-template></xsl:variable>
    85 	<!-- <xsl:variable name="this" select="$thisDoc/item[@id=$topic]" /> -->
    86 	<!-- <xsl:variable name="name" select="$this/@name" /> -->
    87 	<xsl:variable name="name"><xsl:call-template name="getTopicName"><xsl:with-param name="id" select="$topic" /></xsl:call-template></xsl:variable>
    88 	
    89 	<xsl:variable name="escaped-start"    select="substring-after( $content, '\{' )" />
    90 	<xsl:variable name="item-start"       select="substring-before( $content, '{' )" />
    91 
    92 	<xsl:variable name="item-end"         select="substring-after( $content, '}' )" />
    93 	<xsl:variable name="escaped-end"      select="substring-after( $content, '\}' )" />
    94 
    95 	<xsl:if test="string(normalize-space($item-start))">
    96 		<xsl:if test="normalize-space($escaped-start) != normalize-space($item-start)">
    97 			<xsl:call-template name="lastCall">
    98 				<xsl:with-param name="content" select="$item-start" />
    99 			</xsl:call-template>
   100 		</xsl:if>
   101 		<xsl:if test="normalize-space($escaped-start) = normalize-space($item-start)">
   102 			<xsl:call-template name="lastCall">
   103 				<xsl:with-param name="content" select="$escaped-start" />
   104 			</xsl:call-template>
   105 		</xsl:if>
   106 	</xsl:if>
   107 
   108 	<xsl:variable name="middle">
   109 		<xsl:if test="string(normalize-space($topic))">
   110 		
   111 			<!-- <xsl:value-of select="$topic" />(<xsl:value-of select="substring($topic, 1)" />) -->
   112 			<xsl:choose>
   113 				<xsl:when test="substring($topic, 1, 1) = '('">
   114 				
   115 					<xsl:variable name="tmp"><xsl:value-of select="substring-before( $topic, ')' )" /></xsl:variable>
   116 					<xsl:variable name="thisName" select="substring-after( $topic, ') ' )" />
   117 					<xsl:variable name="name2">
   118 						<xsl:choose>
   119 							<xsl:when test="substring($topic, 2, 1) = '%'"><img src="{substring( $tmp, 3 )}" class="image" border="0" alt="" /></xsl:when>
   120 							<xsl:otherwise><xsl:value-of select="substring( $tmp, 2 )" /></xsl:otherwise>
   121 						</xsl:choose>	
   122 					</xsl:variable>
   123 					<xsl:choose>
   124 						<xsl:when test="starts-with($thisName, 'http')">
   125 							<xsl:element name="a">
   126 								<xsl:attribute name="href"><xsl:value-of select="$thisName" /></xsl:attribute>
   127 								<xsl:if test="substring($topic, 2, 1) != '%'">
   128 									<xsl:attribute name="class">extLink</xsl:attribute>
   129 								</xsl:if><xsl:copy-of select="$name2" />
   130 							</xsl:element>
   131 						</xsl:when>
   132 						<xsl:when test="starts-with($thisName, 'mailto')">
   133 							<xsl:element name="a">
   134 								<xsl:attribute name="href"><xsl:value-of select="$thisName" /></xsl:attribute>
   135 								<xsl:if test="substring($topic, 2, 1) != '%'">
   136 									<xsl:attribute name="class">extLink</xsl:attribute>
   137 								</xsl:if><xsl:copy-of select="$name2" />
   138 							</xsl:element>
   139 						</xsl:when>
   140 						<xsl:otherwise>
   141 							<xsl:element name="a">
   142 								<xsl:attribute name="href"><xsl:value-of select="$thisName" />.html</xsl:attribute>
   143 								<xsl:if test="not(substring($topic, 2, 1) = '%')">
   144 									<xsl:attribute name="class">topicLink</xsl:attribute>
   145 								</xsl:if>
   146 								<xsl:copy-of select="$name2" />
   147 							</xsl:element>
   148 						</xsl:otherwise>
   149 					</xsl:choose>
   150 	
   151 				</xsl:when>
   152 				<xsl:when test="substring($topic, 1, 1) = '!' and string($supportMenu)">
   153 					<menu style="{substring-after($topic, '!')}"/>
   154 				</xsl:when>
   155 				<xsl:when test="substring($topic, 1, 1) = '#' and string($supportShowme)">
   156 					<show-me what="{substring-after($topic, '#')}" id="{$currentID}" />
   157 				</xsl:when>
   158 				<xsl:when test="substring($topic, 1, 1) = '+' and string($supportSource)">
   159 					<div class="viewSource"><a href="content/{$currentID}.orig" class="viewSource">view content source file</a></div>
   160 				</xsl:when>
   161 				<xsl:when test="substring($topic, 1, 1) = '%' and string($supportImage)">
   162 					<image href="{substring-after($topic, '%')}" id="{$currentID}" />
   163 				</xsl:when>
   164 				<xsl:when test="starts-with($topic, 'http')">
   165 					<xsl:element name="a">
   166 						<xsl:attribute name="href"><xsl:value-of select="$topic" /></xsl:attribute>
   167 						<xsl:attribute name="class">extLink</xsl:attribute><xsl:value-of select="$topic" />
   168 					</xsl:element>
   169 				</xsl:when>
   170 				<xsl:otherwise>
   171 					<xsl:element name="a">
   172 						<xsl:attribute name="href"><xsl:value-of select="$topic" />.html</xsl:attribute>
   173 						<xsl:attribute name="class">topicLink</xsl:attribute><xsl:value-of select="$name" />
   174 					</xsl:element>
   175 				</xsl:otherwise>
   176 			</xsl:choose>
   177 			
   178 		</xsl:if>
   179 	</xsl:variable>
   180 
   181 			<xsl:call-template name="lastCall">
   182 				<xsl:with-param name="content" select="$middle" />
   183 			</xsl:call-template>
   184 <!-- 	<xsl:copy-of select="$middle" />
   185  -->
   186 	<xsl:variable name="more">
   187 		<xsl:call-template name="findNext">
   188 			<xsl:with-param name="content" select="$item-end" />
   189 		</xsl:call-template>
   190 	</xsl:variable>
   191 	
   192 	<xsl:choose>
   193 		<xsl:when test="string(normalize-space($more))">
   194 			<xsl:call-template name="replace-tags"><xsl:with-param name="content" select="$item-end" /><xsl:with-param name="currentID" select="$currentID" /></xsl:call-template>
   195 		</xsl:when>
   196 		<xsl:otherwise>
   197 			<xsl:if test="string(normalize-space($item-end))">
   198 				<xsl:call-template name="lastCall">
   199 					<xsl:with-param name="content" select="$item-end" />
   200 				</xsl:call-template>
   201 <!-- 				<xsl:copy-of select="$item-end" />
   202  -->			</xsl:if>
   203 		</xsl:otherwise>
   204 	</xsl:choose>
   205 
   206 	<xsl:if test="not(string(normalize-space($item-start))) and not(string(normalize-space($item-end))) and not(string(normalize-space($topic)))">
   207 			<xsl:call-template name="lastCall">
   208 				<xsl:with-param name="content" select="$content" />
   209 			</xsl:call-template>
   210 <!-- 		<xsl:copy-of select="$content" /> -->
   211 	</xsl:if>
   212 
   213 </xsl:template>
   214 
   215 <xsl:template name="markupLine">
   216 	<xsl:param name="content" />
   217 	<xsl:param name="currentID" />
   218 	<xsl:variable name="first" select="substring($content, 1, 1)" />
   219 	<xsl:variable name="c">
   220 		<xsl:if test="$wikistyle">
   221 		  <xsl:if test="string($first) = '?'">question</xsl:if>
   222 		  <xsl:if test="string($first) = '='">answer</xsl:if>
   223 		  <xsl:if test="string($first) = '!'">note</xsl:if>
   224 		  <xsl:if test="string($first) = '*'">point</xsl:if>
   225 		  <xsl:if test="string($first) = '.'">indent</xsl:if>
   226 		  <xsl:if test="string($first) = '|'">code</xsl:if>
   227 		  <xsl:if test="string($first) = ':'">blank</xsl:if>
   228 		  <xsl:if test="string($first) = '-'">headerSmall</xsl:if>
   229 		  <xsl:if test="string($first) = '+'">headerLarge</xsl:if>
   230 		  <xsl:if test="string($first) = '#'">meta</xsl:if>
   231 		</xsl:if>
   232 		<xsl:if test="not($wikistyle)"></xsl:if>
   233 	</xsl:variable>
   234 
   235 	<!-- <xsl:message>
   236 		<xsl:text>c: </xsl:text><xsl:value-of select="$c"/>
   237 		<xsl:text> wikistyle: </xsl:text><xsl:value-of select="$wikistyle"/>
   238 	</xsl:message> -->
   239 	
   240 	<xsl:variable name="cont">
   241 		<xsl:if test="string($c) and $wikistyle">
   242 			<xsl:copy-of select="substring($content, 2)" /></xsl:if>
   243 		<xsl:if test="not(string($c))">
   244 			<xsl:copy-of select="$content" /></xsl:if>
   245 	</xsl:variable>
   246 	
   247 	<xsl:variable name="class">
   248 		<xsl:if test="string($c)">
   249 			<xsl:copy-of select="$c" /></xsl:if>
   250 		<xsl:if test="not(string($c))">normal</xsl:if>
   251 	</xsl:variable>
   252 	
   253 	<xsl:choose>
   254 		<xsl:when test="$c = 'meta'">
   255 			<xsl:variable name="what" select="$cont" />
   256 			<xsl:variable name="before" select="substring-before($what, '=')" />
   257 			<xsl:variable name="after" select="substring-after($what, '=')" />
   258 			<xsl:if test="string($before)">
   259 				<xsl:text disable-output-escaping="yes"><![CDATA[<]]></xsl:text><xsl:copy-of select="normalize-space($before)" /><xsl:text disable-output-escaping="yes"><![CDATA[>]]></xsl:text>
   260 					<xsl:copy-of select="$after" />
   261 				<xsl:text disable-output-escaping="yes"><![CDATA[</]]></xsl:text><xsl:copy-of select="normalize-space($before)" /><xsl:text disable-output-escaping="yes"><![CDATA[>]]></xsl:text>
   262 			</xsl:if>
   263 		</xsl:when>
   264 		<xsl:when test="$c = 'code'">
   265 			<p class="{$class}"><xsl:copy-of select="$cont" /></p>
   266 		</xsl:when>
   267 		<xsl:when test="not($wikistyle)">
   268 			<p class="{$class}"><xsl:copy-of select="$cont" /></p>
   269 			<!-- <xsl:message terminate="yes" /> -->
   270 		</xsl:when>
   271 		<xsl:otherwise>
   272 			<p class="{$class}"><xsl:call-template name="replace-tags"><xsl:with-param name="content" select="$cont" /><xsl:with-param name="currentID" select="$currentID" /></xsl:call-template></p>
   273 		</xsl:otherwise>
   274 	</xsl:choose>
   275 </xsl:template>
   276 
   277 <xsl:template name="doLine">
   278 	<xsl:param name="content" />
   279 	<xsl:param name="currentID" />
   280 	<xsl:variable name="line" select="normalize-space(concat( substring-before( $content, $controlCharacter ), $controlCharacter))" />
   281 	<xsl:variable name="lineClear" select="normalize-space(translate( $line,  $controlCharacter, ' ' ))" />
   282 	<xsl:variable name="next" select="normalize-space(substring-after( $content, $line ))" />
   283 <!-- 	[<xsl:value-of select="$content" />]<br/>
   284 	[<xsl:value-of select="$line" />]<br/>
   285 	[<xsl:value-of select="$lineClear" />]<br/>
   286 	[<xsl:value-of select="$next" />]<br/> -->
   287 	<xsl:if test="string(normalize-space($lineClear))">
   288 		<xsl:call-template name="markupLine"><xsl:with-param name="content"><xsl:copy-of select="$lineClear" /></xsl:with-param><xsl:with-param name="currentID" select="$currentID" /></xsl:call-template>
   289 	</xsl:if>
   290 	<xsl:if test="string(normalize-space($next))">
   291 		<xsl:call-template name="doLine"><xsl:with-param name="content"><xsl:copy-of select="$next" /></xsl:with-param><xsl:with-param name="currentID" select="$currentID" /></xsl:call-template>
   292 	</xsl:if>
   293 </xsl:template>
   294 
   295 </xsl:stylesheet>