-<xsl:template name="space">
- <xsl:param name="repeat">0</xsl:param>
- <xsl:param name="fill" select="' '"/>
- <xsl:if test="number($repeat) >= 1">
- <xsl:call-template name="space">
- <xsl:with-param name="repeat" select="$repeat - 1"/>
- <xsl:with-param name="fill" select="$fill"/>
- </xsl:call-template>
- <xsl:value-of select="$fill"/>
- </xsl:if>
+<xsl:template name="line-wrap">
+ <xsl:param name="line-length"/> <!-- required -->
+ <xsl:param name="first-line-length" select="$line-length"/>
+ <xsl:param name="text"/> <!-- required -->
+ <xsl:choose>
+ <xsl:when test="normalize-space($text) = ''" />
+ <xsl:when test="string-length($text) <= $first-line-length">
+ <xsl:value-of select="concat($text, ' ')" />
+ </xsl:when>
+ <xsl:otherwise>
+ <xsl:variable name="break-pos">
+ <xsl:call-template name="ws-search">
+ <xsl:with-param name="text" select="$text" />
+ <xsl:with-param name="start" select="$first-line-length+1" />
+ </xsl:call-template>
+ </xsl:variable>
+ <xsl:value-of select="substring($text, 1, $break-pos - 1)" />
+ <xsl:text> </xsl:text>
+ <xsl:call-template name="line-wrap">
+ <xsl:with-param name="line-length" select="$line-length" />
+ <xsl:with-param
+ name="text" select="concat(' ', substring($text, $break-pos+1))"
+ />
+ </xsl:call-template>
+ </xsl:otherwise>
+ </xsl:choose>
+</xsl:template>
+
+<xsl:template name="ws-search">
+ <xsl:param name="text"/> <!-- required -->
+ <xsl:param name="start"/> <!-- required -->
+ <xsl:variable name="search-text" select="substring($text, $start)" />
+ <xsl:choose>
+ <xsl:when test="not(contains($search-text, ' '))">
+ <xsl:value-of select="string-length($text)+1" />
+ </xsl:when>
+ <xsl:otherwise>
+ <xsl:value-of
+ select="$start + string-length(substring-before($search-text, ' '))"
+ />
+ </xsl:otherwise>
+ </xsl:choose>