first commit
[community-lisp-ru.git] / rulisp / src / content.xsl
blobf60a6d1cb1bdbc4a0f1ce4ac23fa40b3a0a04014
1 <?xml version="1.0" encoding="utf-8"?>
3 <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
4 xmlns:xlink="http://www.w3.org/1999/xlink"
5 version="1.0">
7 <xsl:template match="/page">
8 <overlay>
9 <head>
10 <title>common.lisp.ru - <xsl:value-of select="@xlink:title" /></title>
11 </head>
13 <div id="content">
14 <xsl:apply-templates select="*|text()" />
15 </div>
16 </overlay>
17 </xsl:template>
19 <!-- //////////////////////////////////////////////////////////////////////////////////////////////////// -->
20 <!-- //////////////////////////////////////////////////////////////////////////////////////////////////// -->
22 <xsl:template match="title" />
24 <xsl:template match="code">
25 <pre class="code">
26 <!--<xsl:value-of select="normalize-space(.)" />-->
27 <xsl:call-template name="multiline-string">
28 <xsl:with-param name="str" select="string(.)" />
29 <xsl:with-param name="trim">
30 <xsl:call-template name="left-trim-count">
31 <xsl:with-param name="str" select="string(.)" />
32 </xsl:call-template>
33 </xsl:with-param>
34 </xsl:call-template>
35 </pre>
36 </xsl:template>
38 <xsl:template match="*|text()">
39 <xsl:copy>
40 <xsl:copy-of select="@*" />
41 <xsl:apply-templates select="node()|text()" />
42 </xsl:copy>
43 </xsl:template>
46 <!-- //////////////////////////////////////////////////////////////////////////////////////////////////// -->
47 <!-- //////////////////////////////////////////////////////////////////////////////////////////////////// -->
49 <xsl:template name="starts-space-count">
50 <xsl:param name="str" />
51 <xsl:param name="count" select="0" />
53 <xsl:choose>
54 <xsl:when test="normalize-space($str) = ''">1000</xsl:when>
56 <xsl:when test="substring($str, 1, 1) = ' '">
57 <xsl:call-template name="starts-space-count">
58 <xsl:with-param name="str" select="substring($str, 2)" />
59 <xsl:with-param name="count" select="$count + 1" />
60 </xsl:call-template>
61 </xsl:when>
63 <xsl:otherwise>
64 <xsl:value-of select="$count" />
65 </xsl:otherwise>
66 </xsl:choose>
67 </xsl:template>
69 <xsl:template name="left-trim-count">
70 <xsl:param name="str" />
71 <xsl:param name="count" select="1000" />
73 <xsl:variable name="before" select="substring-before($str, '&#xA;')" />
74 <xsl:variable name="after" select="substring-after($str, '&#xA;')" />
76 <xsl:variable name="left">
77 <xsl:call-template name="starts-space-count">
78 <xsl:with-param name="str" select="$before" />
79 </xsl:call-template>
80 </xsl:variable>
82 <xsl:variable name="right">
83 <xsl:choose>
84 <xsl:when test="not($after = '')">
85 <xsl:call-template name="left-trim-count">
86 <xsl:with-param name="str" select="$after" />
87 </xsl:call-template>
88 </xsl:when>
90 <xsl:otherwise>
91 <xsl:value-of select="$count" />
92 </xsl:otherwise>
93 </xsl:choose>
94 </xsl:variable>
96 <xsl:choose>
97 <xsl:when test="$left &lt; $right">
98 <xsl:value-of select="$left" />
99 </xsl:when>
101 <xsl:otherwise>
102 <xsl:value-of select="$right" />
103 </xsl:otherwise>
104 </xsl:choose>
106 </xsl:template>
109 <xsl:template name="multiline-string">
110 <xsl:param name="str" />
111 <xsl:param name="trim" select="0" />
112 <xsl:param name="first" select="'true'" />
114 <xsl:if test="$str and not(normalize-space($str) = '')">
115 <xsl:if test="not($first = 'true')">
116 <br />
117 </xsl:if>
119 <xsl:variable name="line" select="substring(substring-before($str, '&#xA;'), $trim + 1)" />
120 <xsl:value-of select="$line" />
122 <xsl:variable name="nextfirst">
123 <xsl:choose>
124 <xsl:when test="normalize-space($line) = ''"><xsl:text>true</xsl:text></xsl:when>
125 <xsl:otherwise><xsl:text>false</xsl:text></xsl:otherwise>
126 </xsl:choose>
127 </xsl:variable>
129 <xsl:call-template name="multiline-string">
130 <xsl:with-param name="str" select="substring-after($str, '&#xA;')" />
131 <xsl:with-param name="trim" select="$trim" />
132 <xsl:with-param name="first" select="$nextfirst" />
133 </xsl:call-template>
134 </xsl:if>
135 </xsl:template>
136 </xsl:stylesheet>