home *** CD-ROM | disk | FTP | other *** search
/ PC Professionell 2004 December / PCpro_2004_12.ISO / files / webserver / xampp / xampp-cocoon-addon-1.4.9-installer.exe / wrap2para.xsl < prev    next >
Encoding:
Extensible Markup Language  |  2004-07-12  |  3.5 KB  |  91 lines

  1. <?xml version="1.0"?>
  2. <!--
  3.   Copyright 1999-2004 The Apache Software Foundation
  4.  
  5.   Licensed under the Apache License, Version 2.0 (the "License");
  6.   you may not use this file except in compliance with the License.
  7.   You may obtain a copy of the License at
  8.  
  9.       http://www.apache.org/licenses/LICENSE-2.0
  10.  
  11.   Unless required by applicable law or agreed to in writing, software
  12.   distributed under the License is distributed on an "AS IS" BASIS,
  13.   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14.   See the License for the specific language governing permissions and
  15.   limitations under the License.
  16. -->
  17. <xsl:stylesheet version="1.0" 
  18.                 xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  19.  
  20. <!-- wrap2para.xsl - text line wrapping
  21.   This stylesheet handles just <source> elements that have PCDATA.
  22.   Any other type of source element is the reponsibility of the caller xslt.
  23. -->
  24.  
  25. <!-- unstructured source is laid out as a sequence of paragraphs -->
  26.  
  27. <xsl:template name="format-source">
  28.   <xsl:param name="source"/>
  29.   <xsl:if test="normalize-space($source)">
  30.     <xsl:choose>
  31.       <xsl:when test="not(contains($source,' '))">
  32.         <xsl:call-template name="format-source-line">
  33.           <xsl:with-param name="line" select="$source"/>
  34.         </xsl:call-template>
  35.       </xsl:when>
  36.       <xsl:otherwise>
  37.         <xsl:call-template name="format-source-line">
  38.           <xsl:with-param name="line" select="substring-before($source,' ')"/>
  39.         </xsl:call-template>
  40.         <xsl:call-template name="format-source">
  41.           <xsl:with-param name="source" select="substring-after($source,' ')"/>
  42.         </xsl:call-template>
  43.       </xsl:otherwise>
  44.     </xsl:choose>
  45.   </xsl:if>
  46. </xsl:template>
  47.  
  48. <xsl:template name="format-source-line">
  49.   <xsl:param name="line"/>
  50.     <xsl:variable name="text" select="normalize-space($line)"/>
  51.     <xsl:variable name="first-non-white-space-character" select="substring($text,1,1)"/>
  52.     <xsl:variable name="leading-spaces" select="string-length(substring-before($line,$first-non-white-space-character))"/>
  53.     <xsl:variable name="text-with-nbsp">
  54.       <xsl:call-template name="no-break-in-strings">
  55.         <xsl:with-param name="line" select="$text"/>
  56.       </xsl:call-template>
  57.     </xsl:variable>
  58.     <p style="margin-top:2pt;margin-bottom:2pt;padding-left:{8+$leading-spaces*4}pt;text-indent:-8pt;font-size:smaller">
  59.       <xsl:value-of select="$text-with-nbsp"/>
  60.     </p>
  61. </xsl:template>
  62.  
  63. <xsl:template name="no-break-in-strings">
  64.   <xsl:param name="line"/>
  65.   <xsl:variable name="quote">"</xsl:variable>
  66.   <xsl:choose>
  67.     <xsl:when test="contains($line,$quote)">
  68.       <xsl:value-of select="substring-before($line,$quote)"/>
  69.       <xsl:text>"</xsl:text>
  70.       <xsl:variable name="remainder" select="substring-after($line,$quote)"/>
  71.       <xsl:choose>
  72.         <xsl:when test="contains($remainder,$quote)">
  73.           <xsl:variable name="string" select="substring-before($remainder,$quote)"/>
  74.           <xsl:value-of select="translate($string,' ',' ')"/>
  75.       <xsl:text>"</xsl:text>
  76.           <xsl:call-template name="no-break-in-strings">
  77.             <xsl:with-param name="line" select="substring-after($remainder,$quote)"/>
  78.           </xsl:call-template>
  79.         </xsl:when>
  80.         <xsl:otherwise>                
  81.           <xsl:value-of select="translate($remainder,' ',' ')"/>
  82.         </xsl:otherwise>
  83.       </xsl:choose>
  84.     </xsl:when>
  85.     <xsl:otherwise><xsl:value-of select="$line"/></xsl:otherwise>
  86.   </xsl:choose>
  87. </xsl:template>
  88.  
  89. </xsl:stylesheet>
  90.  
  91.