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