(no commit message)
[utils] / crawler / kiss / conf / kiss / utilities.xsl
1 <?xml version="1.0" encoding="UTF-8"?>
2
3 <!-- Note the declaration of the namespace for XInclude. -->
4 <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0"
5   xmlns:xi="http://www.w3.org/2001/XInclude">
6   
7   
8   <xsl:variable name="newline">
9     <xsl:text>&#10;</xsl:text>
10   </xsl:variable>
11   
12   <xsl:variable name="carriageReturn">
13     <xsl:text>&#13;&#10;</xsl:text>
14   </xsl:variable>
15   
16   <!-- =====================================================
17     Replace one string by another
18     - src: string to do substituion in
19     - from: literal string to replace
20     - to:substitution string.
21     ======================================================-->
22   <xsl:template name="string-replace">
23     <xsl:param name="src"/>
24     <xsl:param name="from"/>
25     <xsl:param name="to"/>
26     <xsl:choose>
27       <xsl:when test="contains($src, $from)">
28         <xsl:value-of select="substring-before($src, $from)"/>
29         <xsl:value-of select="$to"/>
30         <xsl:call-template name="string-replace">
31           <xsl:with-param name="src" select="substring-after($src, $from)"/>
32           <xsl:with-param name="from" select="$from"/>
33           <xsl:with-param name="to" select="$to"/>
34         </xsl:call-template>
35       </xsl:when>
36       <xsl:otherwise>
37         <xsl:value-of select="$src"/>
38       </xsl:otherwise>
39     </xsl:choose>
40   </xsl:template>
41   
42   <xsl:template name="indent">
43     <xsl:param name="src"/>
44     <xsl:param name="indentString"/>
45     <xsl:value-of select="$indentString"/>
46     <xsl:call-template name="string-replace">
47       <xsl:with-param name="src"><xsl:value-of select="$src"/></xsl:with-param>
48       <xsl:with-param name="from"><xsl:value-of select="$newline"/></xsl:with-param>
49       <xsl:with-param name="to">
50         <xsl:value-of select="$newline"/>
51         <xsl:value-of select="$indentString"/>
52       </xsl:with-param>
53     </xsl:call-template>
54   </xsl:template>
55   
56   <xsl:template name="word-wrap">
57     <xsl:param name="src"/>
58     <xsl:param name="width"/>
59     
60     <xsl:call-template name="word-wrap-impl">
61       <xsl:with-param name="src">
62         <xsl:call-template name="string-replace">
63           <xsl:with-param name="src">
64             <xsl:value-of select="$src"/>     
65           </xsl:with-param>
66           <xsl:with-param name="from"><xsl:text>  </xsl:text></xsl:with-param>
67           <xsl:with-param name="to"><xsl:text> </xsl:text></xsl:with-param>
68         </xsl:call-template>
69       </xsl:with-param>
70       <xsl:with-param name="width"><xsl:value-of select="$width"/></xsl:with-param>
71       <xsl:with-param name="index"><xsl:value-of select="0"/></xsl:with-param>
72     </xsl:call-template>
73   </xsl:template>
74   
75   <xsl:template name="word-wrap-impl">
76     <xsl:param name="src"/>
77     <xsl:param name="index"/>
78     <xsl:param name="width"/>
79     
80     <xsl:variable name="word">
81       <xsl:value-of select="substring-before($src, ' ')"></xsl:value-of>
82     </xsl:variable>
83     <xsl:variable name="wordlength">
84       <xsl:value-of select="string-length($word)"/>
85     </xsl:variable>
86     <xsl:variable name="remainder">
87       <xsl:value-of select="substring($src, $wordlength+2)"/>
88     </xsl:variable>
89     
90     <xsl:if test="string-length($remainder) > 0">
91       
92       <!-- xsl:value-of select="$wordlength"></xsl:value-of -->
93       <xsl:value-of select="$word"/><xsl:text> </xsl:text>
94       <!-- xsl:value-of select="$index"/ -->
95       <xsl:choose>
96         <xsl:when test="$index + $wordlength + 1 &gt; $width">
97           <xsl:value-of select="$newline"/>
98           <xsl:call-template name="word-wrap-impl">
99             <xsl:with-param name="src"><xsl:value-of select="$remainder"></xsl:value-of></xsl:with-param>
100             <xsl:with-param name="index"><xsl:value-of select="0"/></xsl:with-param>
101             <xsl:with-param name="width"><xsl:value-of select="$width"></xsl:value-of></xsl:with-param>
102           </xsl:call-template>
103         </xsl:when>
104         <xsl:otherwise>
105           <xsl:call-template name="word-wrap-impl">
106             <xsl:with-param name="src"><xsl:value-of select="$remainder"></xsl:value-of></xsl:with-param>
107             <xsl:with-param name="index"><xsl:value-of select="$index + $wordlength+1"/></xsl:with-param>
108             <xsl:with-param name="width"><xsl:value-of select="$width"></xsl:value-of></xsl:with-param>
109           </xsl:call-template>
110         </xsl:otherwise>
111       </xsl:choose>
112      
113       
114     </xsl:if>
115   </xsl:template>
116   
117 </xsl:stylesheet>