Project

Profile

Help

Bug #3055 » novatchev-getLines-fails.xsl

Radu Coravu, 2016-12-01 08:30

 
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:ta="http://www.ixxus.co.uk/model/ta-cms/1.0"
xmlns:cm="http://www.alfresco.org/model/content/1.0" xmlns:sem="http://marklogic.com/semantics"
xmlns:rsc="http://www.retrievalsystems.com/tafuncs" exclude-result-prefixes="xs" version="2.0">

<xsl:output method="text"/>

<xsl:template match="/*/text()" name="reformat">
<xsl:param name="pText" select="translate(., '&#xA;', ' ')"/>
<xsl:param name="pMaxLength" select="64"/>
<xsl:param name="pTotalLength" select="string-length(.)"/>
<xsl:param name="pLengthFormatted" select="0"/>

<xsl:if test="not($pLengthFormatted >= $pTotalLength)">
<xsl:variable name="vNextLine"
select="rsc:getLine(substring($pText, $pLengthFormatted + 1), $pMaxLength)"/>
<xsl:sequence select="concat($vNextLine, '&#xA;')"/>

<xsl:call-template name="reformat">
<xsl:with-param name="pText" select="$pText"/>
<xsl:with-param name="pMaxLength" select="$pMaxLength"/>
<xsl:with-param name="pTotalLength" select="$pTotalLength"/>
<xsl:with-param name="pLengthFormatted"
select="$pLengthFormatted + string-length($vNextLine)"/>
</xsl:call-template>
</xsl:if>
</xsl:template>

<xsl:function name="rsc:getLine" as="xs:string?">
<xsl:param name="pText" as="xs:string?"/>
<xsl:param name="pLength" as="xs:integer"/>

<xsl:variable name="vChunk" select="substring($pText, 1, $pLength)"/>
<xsl:message>
<xsl:value-of select="$vChunk"/>
</xsl:message>
<xsl:choose>
<xsl:when
test="
not(string-length($pText) > $pLength)
or matches(substring($pText, $pLength + 1, 1), '\W')">
<xsl:sequence select="$vChunk"/>
</xsl:when>
<xsl:otherwise>
<xsl:analyze-string select="$vChunk"
regex="^((\W*\w*)*?)(\W+\w*)$">
<xsl:matching-substring>
<xsl:message>Saw word: [<xsl:value-of select="regex-group(1)"/>]</xsl:message>
<xsl:sequence select="regex-group(1)"/>
</xsl:matching-substring>
<xsl:non-matching-substring>
<xsl:message>Saw delimiter: [<xsl:value-of select="."/>]</xsl:message>
</xsl:non-matching-substring>
</xsl:analyze-string>
</xsl:otherwise>
</xsl:choose>
</xsl:function>
</xsl:stylesheet>
(1-1/2)