<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<!--xsl:param name="debug" select="'false'"/-->
<xsl:param name="debug" select="'true'"/>
<xsl:param name="ggll" select="45"/>
<xsl:template match="/">
<table border="1">
<xsl:choose>
<xsl:when test="text/highlight[1]">
<xsl:apply-templates select="text/highlight[1]" mode="my"/>
</xsl:when>
<xsl:otherwise>
<tr>
<td>
<xsl:value-of select="substring(text, 0, $ggll)"/>
<xsl:text>...</xsl:text>
</td>
</tr>
</xsl:otherwise>
</xsl:choose>
</table>
</xsl:template>
<xsl:template match="highlight" mode="my">
<xsl:param name="my">
<xsl:apply-templates select="preceding-sibling::text()|preceding-sibling::highlight"/>
</xsl:param>
<xsl:param name="sta"/>
<xsl:param name="end"/>
<xsl:param name="curSta">
<xsl:choose>
<xsl:when test="$sta">
<xsl:value-of select="concat($sta, string-length($my))"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="string-length($my)"/>
</xsl:otherwise>
</xsl:choose>
</xsl:param>
<xsl:param name="curEnd">
<xsl:choose>
<xsl:when test="$end">
<xsl:value-of select="concat($end, string-length($my) + string-length(.))"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="string-length($my) + string-length(.)"/>
</xsl:otherwise>
</xsl:choose>
</xsl:param>
<xsl:param name="myLast" select="following-sibling::text()[1]"/>
<xsl:choose>
<xsl:when test="following-sibling::highlight[1]">
<xsl:apply-templates select="following-sibling::highlight[1]" mode="my">
<xsl:with-param name="sta" select="concat($curSta, ',')"/>
<xsl:with-param name="end" select="concat($curEnd, ',')"/>
</xsl:apply-templates>
</xsl:when>
<xsl:otherwise>
<xsl:call-template name="seeOut">
<xsl:with-param name="sta" select="concat($curSta, ',')"/>
<xsl:with-param name="end" select="concat($curEnd, ',')"/>
<xsl:with-param name="my" select="concat($my, ., $myLast)"/>
</xsl:call-template>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template name="seeOut">
<xsl:param name="sta"/>
<xsl:param name="end"/>
<xsl:param name="my"/>
<xsl:param name="count" select="1"/>
<xsl:param name="acum"/>
<xsl:if test="$debug = 'true' and $count > 1">
<xsl:call-template name="doText">
<xsl:with-param name="my" select="$my"/>
<xsl:with-param name="acum" select="$acum"/>
</xsl:call-template>
</xsl:if>
<xsl:choose>
<xsl:when test="$ggll >= $count">
<xsl:call-template name="seeOut">
<xsl:with-param name="sta">
<xsl:choose>
<xsl:when test="$count >= substring-before($end, ',')">
<xsl:value-of select="substring-after($sta, ',')"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$sta"/>
</xsl:otherwise>
</xsl:choose>
</xsl:with-param>
<xsl:with-param name="end">
<xsl:choose>
<xsl:when test="$count >= substring-before($end, ',')">
<xsl:value-of select="substring-after($end, ',')"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$end"/>
</xsl:otherwise>
</xsl:choose>
</xsl:with-param>
<xsl:with-param name="my" select="$my"/>
<xsl:with-param name="count" select="$count + 1"/>
<xsl:with-param name="acum">
<xsl:copy-of select="$acum"/>
<xsl:choose>
<xsl:when test="$count > substring-before($sta, ',') and substring-before($end, ',') >= $count">
<b><xsl:value-of select="substring($my, $count, 1)"/></b>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="substring($my, $count, 1)"/>
</xsl:otherwise>
</xsl:choose>
</xsl:with-param>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:if test="$debug = 'false'">
<xsl:call-template name="doText">
<xsl:with-param name="my" select="$my"/>
<xsl:with-param name="acum" select="$acum"/>
</xsl:call-template>
</xsl:if>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template name="doText">
<xsl:param name="my"/>
<xsl:param name="acum"/>
<tr>
<td>
<xsl:copy-of select="$acum"/>
<xsl:if test="string-length(normalize-space($my)) > $ggll">...</xsl:if>
</td>
</tr>
</xsl:template>
</xsl:stylesheet>