(no commit message)
[utils] / crawler / kiss / conf / kiss / utilities.xsl
index 04e4c6867de8d65bf3df096b275c645e92156f70..e6863db215bbe0e0842b3078edad149fd48ba1c1 100644 (file)
@@ -12,7 +12,7 @@
   <xsl:variable name="carriageReturn">
     <xsl:text>&#13;&#10;</xsl:text>
   </xsl:variable>
-
+  
   <!-- =====================================================
     Replace one string by another
     - src: string to do substituion in
     </xsl:choose>
   </xsl:template>
   
+  <xsl:template name="indent">
+    <xsl:param name="src"/>
+    <xsl:param name="indentString"/>
+    <xsl:value-of select="$indentString"/>
+    <xsl:call-template name="string-replace">
+      <xsl:with-param name="src"><xsl:value-of select="$src"/></xsl:with-param>
+      <xsl:with-param name="from"><xsl:value-of select="$newline"/></xsl:with-param>
+      <xsl:with-param name="to">
+        <xsl:value-of select="$newline"/>
+        <xsl:value-of select="$indentString"/>
+      </xsl:with-param>
+    </xsl:call-template>
+  </xsl:template>
+  
+  <xsl:template name="word-wrap">
+    <xsl:param name="src"/>
+    <xsl:param name="width"/>
+    
+    <xsl:call-template name="word-wrap-impl">
+      <xsl:with-param name="src">
+        <xsl:call-template name="string-replace">
+          <xsl:with-param name="src">
+            <xsl:value-of select="$src"/>     
+          </xsl:with-param>
+          <xsl:with-param name="from"><xsl:text>  </xsl:text></xsl:with-param>
+          <xsl:with-param name="to"><xsl:text> </xsl:text></xsl:with-param>
+        </xsl:call-template>
+      </xsl:with-param>
+      <xsl:with-param name="width"><xsl:value-of select="$width"/></xsl:with-param>
+      <xsl:with-param name="index"><xsl:value-of select="0"/></xsl:with-param>
+    </xsl:call-template>
+  </xsl:template>
+  
+  <xsl:template name="word-wrap-impl">
+    <xsl:param name="src"/>
+    <xsl:param name="index"/>
+    <xsl:param name="width"/>
+    
+    <xsl:variable name="word">
+      <xsl:value-of select="substring-before($src, ' ')"></xsl:value-of>
+    </xsl:variable>
+    <xsl:variable name="wordlength">
+      <xsl:value-of select="string-length($word)"/>
+    </xsl:variable>
+    <xsl:variable name="remainder">
+      <xsl:value-of select="substring($src, $wordlength+2)"/>
+    </xsl:variable>
+    
+    <xsl:value-of select="$word"/><xsl:text> </xsl:text>
+    
+    <xsl:if test="string-length($remainder) > 0">
+      
+      <!-- xsl:value-of select="$index"/ -->
+      <xsl:choose>
+        <xsl:when test="$index + $wordlength + 1 &gt; $width">
+          <xsl:value-of select="$newline"/>
+          <xsl:call-template name="word-wrap-impl">
+            <xsl:with-param name="src"><xsl:value-of select="$remainder"></xsl:value-of></xsl:with-param>
+            <xsl:with-param name="index"><xsl:value-of select="0"/></xsl:with-param>
+            <xsl:with-param name="width"><xsl:value-of select="$width"></xsl:value-of></xsl:with-param>
+          </xsl:call-template>
+        </xsl:when>
+        <xsl:otherwise>
+          <xsl:call-template name="word-wrap-impl">
+            <xsl:with-param name="src"><xsl:value-of select="$remainder"></xsl:value-of></xsl:with-param>
+            <xsl:with-param name="index"><xsl:value-of select="$index + $wordlength+1"/></xsl:with-param>
+            <xsl:with-param name="width"><xsl:value-of select="$width"></xsl:value-of></xsl:with-param>
+          </xsl:call-template>
+        </xsl:otherwise>
+      </xsl:choose>
+     
+      
+    </xsl:if>
+  </xsl:template>
+  
 </xsl:stylesheet>