Из комментариев ОП :
Когда я обрабатываю любой текстовый узел, мне нужна сумма предыдущих текстовых узлов.Пытаясь найти, как я могу достичь этого без избыточности, используя функцию previous-text-length
Здесь идет функциональное программирование и функции высшего порядка (HOF), реализованные FXSL library :
Вот полный пример кода. Это преобразование объединяет текстовые узлы XML-документа только до заданного ограничения общей длины:
<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:foldl-func="foldl-func"
xmlns:f="http://fxsl.sf.net/"
exclude-result-prefixes="f foldl-func"
>
<xsl:import href="../f/func-foldl.xsl"/>
<xsl:output method="text"/>
<xsl:strip-space elements="*"/>
<xsl:template match="/">
<xsl:variable name="vinitParam" select="100,0,''"/>
<xsl:value-of select="f:foldl(f:limitedConcat(), $vinitParam, //text() )"/>
</xsl:template>
<xsl:function name="f:limitedConcat">
<xsl:param name="pAccumResults"/>
<xsl:param name="pcurrentNode" as="text()"/>
<xsl:variable name="vLengthLimit" select="$pAccumResults[1]"/>
<xsl:variable name="vAccumLength" select="$pAccumResults[2]"/>
<xsl:sequence select=
"for $vNewLength in $vAccumLength+string-length($pcurrentNode),
$vInLimit in ($vNewLength le $vLengthLimit)
return
($vLengthLimit,
(if($vInLimit)
then $vNewLength
else $vAccumLength) ,
if($vInLimit)
then concat($pAccumResults[3], $pcurrentNode)
else $pAccumResults[3]
)
"/>
</xsl:function>
<xsl:function name="f:limitedConcat" as="element()">
<f:limitedConcat/>
</xsl:function>
<xsl:template match="f:limitedConcat" mode="f:FXSL">
<xsl:param name="arg1"/>
<xsl:param name="arg2"/>
<xsl:sequence select="f:limitedConcat($arg1,$arg2)"/>
</xsl:template>
</xsl:stylesheet>
При применении к этому документу XML :
<booklist>
<book>
<title>Angela's Ashes</title>
<author>Frank McCourt</author>
<publisher>HarperCollins</publisher>
<isbn>0 00 649840 X</isbn>
<price>6.99</price>
<sales>235</sales>
</book>
<book>
<title>Sword of Honour</title>
<author>Evelyn Waugh</author>
<publisher>Penguin Books</publisher>
<isbn>0 14 018967 X</isbn>
<price>12.99</price>
<sales>12</sales>
</book>
<book>
<title>Angela's Ashes</title>
<author>Frank McCourt</author>
<publisher>HarperCollins</publisher>
<isbn>0 00 649840 X</isbn>
<price>6.99</price>
<sales>235</sales>
</book>
<book>
<title>Sword of Honour</title>
<author>Evelyn Waugh</author>
<publisher>Penguin Books</publisher>
<isbn>0 14 018967 X</isbn>
<price>12.99</price>
<sales>12</sales>
</book>
<book>
<title>Angela's Ashes</title>
<author>Frank McCourt</author>
<publisher>HarperCollins</publisher>
<isbn>0 00 649840 X</isbn>
<price>6.99</price>
<sales>235</sales>
</book>
<book>
<title>Sword of Honour</title>
<author>Evelyn Waugh</author>
<publisher>Penguin Books</publisher>
<isbn>0 14 018967 X</isbn>
<price>12.99</price>
<sales>12</sales>
</book>
<book>
<title>Angela's Ashes</title>
<author>Frank McCourt</author>
<publisher>HarperCollins</publisher>
<isbn>0 00 649840 X</isbn>
<price>6.99</price>
<sales>235</sales>
</book>
<book>
<title>Sword of Honour</title>
<author>Evelyn Waugh</author>
<publisher>Penguin Books</publisher>
<isbn>0 14 018967 X</isbn>
<price>12.99</price>
<sales>12</sales>
</book>
<book>
<title>Angela's Ashes</title>
<author>Frank McCourt</author>
<publisher>HarperCollins</publisher>
<isbn>0 00 649840 X</isbn>
<price>6.99</price>
<sales>235</sales>
</book>
<book>
<title>Sword of Honour</title>
<author>Evelyn Waugh</author>
<publisher>Penguin Books</publisher>
<isbn>0 14 018967 X</isbn>
<price>12.99</price>
<sales>12</sales>
</book>
<book>
<title>Angela's Ashes</title>
<author>Frank McCourt</author>
<publisher>HarperCollins</publisher>
<isbn>0 00 649840 X</isbn>
<price>6.99</price>
<sales>235</sales>
</book>
<book>
<title>Sword of Honour</title>
<author>Evelyn Waugh</author>
<publisher>Penguin Books</publisher>
<isbn>0 14 018967 X</isbn>
<price>12.99</price>
<sales>12</sales>
</book>
<book>
<title>Angela's Ashes</title>
<author>Frank McCourt</author>
<publisher>HarperCollins</publisher>
<isbn>0 00 649840 X</isbn>
<price>6.99</price>
<sales>235</sales>
</book>
<book>
<title>Sword of Honour</title>
<author>Evelyn Waugh</author>
<publisher>Penguin Books</publisher>
<isbn>0 14 018967 X</isbn>
<price>12.99</price>
<sales>12</sales>
</book>
<book>
<title>Angela's Ashes</title>
<author>Frank McCourt</author>
<publisher>HarperCollins</publisher>
<isbn>0 00 649840 X</isbn>
<price>6.99</price>
<sales>235</sales>
</book>
<book>
<title>Sword of Honour</title>
<author>Evelyn Waugh</author>
<publisher>Penguin Books</publisher>
<isbn>0 14 018967 X</isbn>
<price>12.99</price>
<sales>12</sales>
</book>
<book>
<title>Angela's Ashes</title>
<author>Frank McCourt</author>
<publisher>HarperCollins</publisher>
<isbn>0 00 649840 X</isbn>
<price>6.99</price>
<sales>235</sales>
</book>
<book>
<title>Sword of Honour</title>
<author>Evelyn Waugh</author>
<publisher>Penguin Books</publisher>
<isbn>0 14 018967 X</isbn>
<price>12.99</price>
<sales>12</sales>
</book>
<book>
<title>Angela's Ashes</title>
<author>Frank McCourt</author>
<publisher>HarperCollins</publisher>
<isbn>0 00 649840 X</isbn>
<price>6.99</price>
<sales>235</sales>
</book>
<book>
<title>Sword of Honour</title>
<author>Evelyn Waugh</author>
<publisher>Penguin Books</publisher>
<isbn>0 14 018967 X</isbn>
<price>12.99</price>
<sales>12</sales>
</book>
<book>
<title>Angela's Ashes</title>
<author>Frank McCourt</author>
<publisher>HarperCollins</publisher>
<isbn>0 00 649840 X</isbn>
<price>6.99</price>
<sales>235</sales>
</book>
<book>
<title>Sword of Honour</title>
<author>Evelyn Waugh</author>
<publisher>Penguin Books</publisher>
<isbn>0 14 018967 X</isbn>
<price>12.99</price>
<sales>12</sales>
</book>
<book>
<title>Angela's Ashes</title>
<author>Frank McCourt</author>
<publisher>HarperCollins</publisher>
<isbn>0 00 649840 X</isbn>
<price>6.99</price>
<sales>235</sales>
</book>
<book>
<title>Sword of Honour</title>
<author>Evelyn Waugh</author>
<publisher>Penguin Books</publisher>
<isbn>0 14 018967 X</isbn>
<price>12.99</price>
<sales>12</sales>
</book>
<book>
<title>Angela's Ashes</title>
<author>Frank McCourt</author>
<publisher>HarperCollins</publisher>
<isbn>0 00 649840 X</isbn>
<price>6.99</price>
<sales>235</sales>
</book>
<book>
<title>Sword of Honour</title>
<author>Evelyn Waugh</author>
<publisher>Penguin Books</publisher>
<isbn>0 14 018967 X</isbn>
<price>12.99</price>
<sales>12</sales>
</book>
<book>
<title>Angela's Ashes</title>
<author>Frank McCourt</author>
<publisher>HarperCollins</publisher>
<isbn>0 00 649840 X</isbn>
<price>6.99</price>
<sales>235</sales>
</book>
<book>
<title>Sword of Honour</title>
<author>Evelyn Waugh</author>
<publisher>Penguin Books</publisher>
<isbn>0 14 018967 X</isbn>
<price>12.99</price>
<sales>12</sales>
</book>
<book>
<title>Angela's Ashes</title>
<author>Frank McCourt</author>
<publisher>HarperCollins</publisher>
<isbn>0 00 649840 X</isbn>
<price>6.99</price>
<sales>235</sales>
</book>
<book>
<title>Sword of Honour</title>
<author>Evelyn Waugh</author>
<publisher>Penguin Books</publisher>
<isbn>0 14 018967 X</isbn>
<price>12.99</price>
<sales>12</sales>
</book>
<book>
<title>Angela's Ashes</title>
<author>Frank McCourt</author>
<publisher>HarperCollins</publisher>
<isbn>0 00 649840 X</isbn>
<price>6.99</price>
<sales>235</sales>
</book>
<book>
<title>Sword of Honour</title>
<author>Evelyn Waugh</author>
<publisher>Penguin Books</publisher>
<isbn>0 14 018967 X</isbn>
<price>12.99</price>
<sales>12</sales>
</book>
<book>
<title>Angela's Ashes</title>
<author>Frank McCourt</author>
<publisher>HarperCollins</publisher>
<isbn>0 00 649840 X</isbn>
<price>6.99</price>
<sales>235</sales>
</book>
<book>
<title>Sword of Honour</title>
<author>Evelyn Waugh</author>
<publisher>Penguin Books</publisher>
<isbn>0 14 018967 X</isbn>
<price>12.99</price>
<sales>12</sales>
</book>
<book>
<title>Angela's Ashes</title>
<author>Frank McCourt</author>
<publisher>HarperCollins</publisher>
<isbn>0 00 649840 X</isbn>
<price>6.99</price>
<sales>235</sales>
</book>
<book>
<title>Sword of Honour</title>
<author>Evelyn Waugh</author>
<publisher>Penguin Books</publisher>
<isbn>0 14 018967 X</isbn>
<price>12.99</price>
<sales>12</sales>
</book>
<book>
<title>Angela's Ashes</title>
<author>Frank McCourt</author>
<publisher>HarperCollins</publisher>
<isbn>0 00 649840 X</isbn>
<price>6.99</price>
<sales>235</sales>
</book>
<book>
<title>Sword of Honour</title>
<author>Evelyn Waugh</author>
<publisher>Penguin Books</publisher>
<isbn>0 14 018967 X</isbn>
<price>12.99</price>
<sales>12</sales>
</book>
<book>
<title>Angela's Ashes</title>
<author>Frank McCourt</author>
<publisher>HarperCollins</publisher>
<isbn>0 00 649840 X</isbn>
<price>6.99</price>
<sales>235</sales>
</book>
<book>
<title>Sword of Honour</title>
<author>Evelyn Waugh</author>
<publisher>Penguin Books</publisher>
<isbn>0 14 018967 X</isbn>
<price>12.99</price>
<sales>12</sales>
</book>
<book>
<title>Angela's Ashes</title>
<author>Frank McCourt</author>
<publisher>HarperCollins</publisher>
<isbn>0 00 649840 X</isbn>
<price>6.99</price>
<sales>235</sales>
</book>
<book>
<title>Sword of Honour</title>
<author>Evelyn Waugh</author>
<publisher>Penguin Books</publisher>
<isbn>0 14 018967 X</isbn>
<price>12.99</price>
<sales>12</sales>
</book>
<book>
<title>Angela's Ashes</title>
<author>Frank McCourt</author>
<publisher>HarperCollins</publisher>
<isbn>0 00 649840 X</isbn>
<price>6.99</price>
<sales>235</sales>
</book>
<book>
<title>Sword of Honour</title>
<author>Evelyn Waugh</author>
<publisher>Penguin Books</publisher>
<isbn>0 14 018967 X</isbn>
<price>12.99</price>
<sales>12</sales>
</book>
<book>
<title>Angela's Ashes</title>
<author>Frank McCourt</author>
<publisher>HarperCollins</publisher>
<isbn>0 00 649840 X</isbn>
<price>6.99</price>
<sales>235</sales>
</book>
<book>
<title>Sword of Honour</title>
<author>Evelyn Waugh</author>
<publisher>Penguin Books</publisher>
<isbn>0 14 018967 X</isbn>
<price>12.99</price>
<sales>12</sales>
</book>
<book>
<title>Angela's Ashes</title>
<author>Frank McCourt</author>
<publisher>HarperCollins</publisher>
<isbn>0 00 649840 X</isbn>
<price>6.99</price>
<sales>235</sales>
</book>
<book>
<title>Sword of Honour</title>
<author>Evelyn Waugh</author>
<publisher>Penguin Books</publisher>
<isbn>0 14 018967 X</isbn>
<price>12.99</price>
<sales>12</sales>
</book>
<book>
<title>Angela's Ashes</title>
<author>Frank McCourt</author>
<publisher>HarperCollins</publisher>
<isbn>0 00 649840 X</isbn>
<price>6.99</price>
<sales>235</sales>
</book>
<book>
<title>Sword of Honour</title>
<author>Evelyn Waugh</author>
<publisher>Penguin Books</publisher>
<isbn>0 14 018967 X</isbn>
<price>12.99</price>
<sales>12</sales>
</book>
<book>
<title>Angela's Ashes</title>
<author>Frank McCourt</author>
<publisher>HarperCollins</publisher>
<isbn>0 00 649840 X</isbn>
<price>6.99</price>
<sales>235</sales>
</book>
<book>
<title>Sword of Honour</title>
<author>Evelyn Waugh</author>
<publisher>Penguin Books</publisher>
<isbn>0 14 018967 X</isbn>
<price>12.99</price>
<sales>12</sales>
</book>
<book>
<title>Angela's Ashes</title>
<author>Frank McCourt</author>
<publisher>HarperCollins</publisher>
<isbn>0 00 649840 X</isbn>
<price>6.99</price>
<sales>235</sales>
</book>
<book>
<title>Sword of Honour</title>
<author>Evelyn Waugh</author>
<publisher>Penguin Books</publisher>
<isbn>0 14 018967 X</isbn>
<price>12.99</price>
<sales>12</sales>
</book>
<book>
<title>Angela's Ashes</title>
<author>Frank McCourt</author>
<publisher>HarperCollins</publisher>
<isbn>0 00 649840 X</isbn>
<price>6.99</price>
<sales>235</sales>
</book>
<book>
<title>Sword of Honour</title>
<author>Evelyn Waugh</author>
<publisher>Penguin Books</publisher>
<isbn>0 14 018967 X</isbn>
<price>12.99</price>
<sales>12</sales>
</book>
<book>
<title>Angela's Ashes</title>
<author>Frank McCourt</author>
<publisher>HarperCollins</publisher>
<isbn>0 00 649840 X</isbn>
<price>6.99</price>
<sales>235</sales>
</book>
<book>
<title>Sword of Honour</title>
<author>Evelyn Waugh</author>
<publisher>Penguin Books</publisher>
<isbn>0 14 018967 X</isbn>
<price>12.99</price>
<sales>12</sales>
</book>
<book>
<title>Angela's Ashes</title>
<author>Frank McCourt</author>
<publisher>HarperCollins</publisher>
<isbn>0 00 649840 X</isbn>
<price>6.99</price>
<sales>235</sales>
</book>
<book>
<title>Sword of Honour</title>
<author>Evelyn Waugh</author>
<publisher>Penguin Books</publisher>
<isbn>0 14 018967 X</isbn>
<price>12.99</price>
<sales>12</sales>
</book>
<book>
<title>Angela's Ashes</title>
<author>Frank McCourt</author>
<publisher>HarperCollins</publisher>
<isbn>0 00 649840 X</isbn>
<price>6.99</price>
<sales>235</sales>
</book>
<book>
<title>Sword of Honour</title>
<author>Evelyn Waugh</author>
<publisher>Penguin Books</publisher>
<isbn>0 14 018967 X</isbn>
<price>12.99</price>
<sales>12</sales>
</book>
<book>
<title>Angela's Ashes</title>
<author>Frank McCourt</author>
<publisher>HarperCollins</publisher>
<isbn>0 00 649840 X</isbn>
<price>6.99</price>
<sales>235</sales>
</book>
<book>
<title>Sword of Honour</title>
<author>Evelyn Waugh</author>
<publisher>Penguin Books</publisher>
<isbn>0 14 018967 X</isbn>
<price>12.99</price>
<sales>12</sales>
</book>
<book>
<title>Angela's Ashes</title>
<author>Frank McCourt</author>
<publisher>HarperCollins</publisher>
<isbn>0 00 649840 X</isbn>
<price>6.99</price>
<sales>235</sales>
</book>
<book>
<title>Sword of Honour</title>
<author>Evelyn Waugh</author>
<publisher>Penguin Books</publisher>
<isbn>0 14 018967 X</isbn>
<price>12.99</price>
<sales>12</sales>
</book>
<book>
<title>Angela's Ashes</title>
<author>Frank McCourt</author>
<publisher>HarperCollins</publisher>
<isbn>0 00 649840 X</isbn>
<price>6.99</price>
<sales>235</sales>
</book>
<book>
<title>Sword of Honour</title>
<author>Evelyn Waugh</author>
<publisher>Penguin Books</publisher>
<isbn>0 14 018967 X</isbn>
<price>12.99</price>
<sales>12</sales>
</book>
<book>
<title>Angela's Ashes</title>
<author>Frank McCourt</author>
<publisher>HarperCollins</publisher>
<isbn>0 00 649840 X</isbn>
<price>6.99</price>
<sales>235</sales>
</book>
<book>
<title>Sword of Honour</title>
<author>Evelyn Waugh</author>
<publisher>Penguin Books</publisher>
<isbn>0 14 018967 X</isbn>
<price>12.99</price>
<sales>12</sales>
</book>
<book>
<title>Angela's Ashes</title>
<author>Frank McCourt</author>
<publisher>HarperCollins</publisher>
<isbn>0 00 649840 X</isbn>
<price>6.99</price>
<sales>235</sales>
</book>
<book>
<title>Sword of Honour</title>
<author>Evelyn Waugh</author>
<publisher>Penguin Books</publisher>
<isbn>0 14 018967 X</isbn>
<price>12.99</price>
<sales>12</sales>
</book>
<book>
<title>Angela's Ashes</title>
<author>Frank McCourt</author>
<publisher>HarperCollins</publisher>
<isbn>0 00 649840 X</isbn>
<price>6.99</price>
<sales>235</sales>
</book>
<book>
<title>Sword of Honour</title>
<author>Evelyn Waugh</author>
<publisher>Penguin Books</publisher>
<isbn>0 14 018967 X</isbn>
<price>12.99</price>
<sales>12</sales>
</book>
<book>
<title>Angela's Ashes</title>
<author>Frank McCourt</author>
<publisher>HarperCollins</publisher>
<isbn>0 00 649840 X</isbn>
<price>6.99</price>
<sales>235</sales>
</book>
<book>
<title>Sword of Honour</title>
<author>Evelyn Waugh</author>
<publisher>Penguin Books</publisher>
<isbn>0 14 018967 X</isbn>
<price>12.99</price>
<sales>12</sales>
</book>
<book>
<title>Angela's Ashes</title>
<author>Frank McCourt</author>
<publisher>HarperCollins</publisher>
<isbn>0 00 649840 X</isbn>
<price>6.99</price>
<sales>235</sales>
</book>
<book>
<title>Sword of Honour</title>
<author>Evelyn Waugh</author>
<publisher>Penguin Books</publisher>
<isbn>0 14 018967 X</isbn>
<price>12.99</price>
<sales>12</sales>
</book>
<book>
<title>Angela's Ashes</title>
<author>Frank McCourt</author>
<publisher>HarperCollins</publisher>
<isbn>0 00 649840 X</isbn>
<price>6.99</price>
<sales>235</sales>
</book>
<book>
<title>Sword of Honour</title>
<author>Evelyn Waugh</author>
<publisher>Penguin Books</publisher>
<isbn>0 14 018967 X</isbn>
<price>12.99</price>
<sales>12</sales>
</book>
<book>
<title>Angela's Ashes</title>
<author>Frank McCourt</author>
<publisher>HarperCollins</publisher>
<isbn>0 00 649840 X</isbn>
<price>6.99</price>
<sales>235</sales>
</book>
<book>
<title>Sword of Honour</title>
<author>Evelyn Waugh</author>
<publisher>Penguin Books</publisher>
<isbn>0 14 018967 X</isbn>
<price>12.99</price>
<sales>12</sales>
</book>
<book>
<title>Angela's Ashes</title>
<author>Frank McCourt</author>
<publisher>HarperCollins</publisher>
<isbn>0 00 649840 X</isbn>
<price>6.99</price>
<sales>235</sales>
</book>
<book>
<title>Sword of Honour</title>
<author>Evelyn Waugh</author>
<publisher>Penguin Books</publisher>
<isbn>0 14 018967 X</isbn>
<price>12.99</price>
<sales>12</sales>
</book>
<book>
<title>Angela's Ashes</title>
<author>Frank McCourt</author>
<publisher>HarperCollins</publisher>
<isbn>0 00 649840 X</isbn>
<price>6.99</price>
<sales>235</sales>
</book>
<book>
<title>Sword of Honour</title>
<author>Evelyn Waugh</author>
<publisher>Penguin Books</publisher>
<isbn>0 14 018967 X</isbn>
<price>12.99</price>
<sales>12</sales>
</book>
<book>
<title>Angela's Ashes</title>
<author>Frank McCourt</author>
<publisher>HarperCollins</publisher>
<isbn>0 00 649840 X</isbn>
<price>6.99</price>
<sales>235</sales>
</book>
<book>
<title>Sword of Honour</title>
<author>Evelyn Waugh</author>
<publisher>Penguin Books</publisher>
<isbn>0 14 018967 X</isbn>
<price>12.99</price>
<sales>12</sales>
</book>
<book>
<title>Angela's Ashes</title>
<author>Frank McCourt</author>
<publisher>HarperCollins</publisher>
<isbn>0 00 649840 X</isbn>
<price>6.99</price>
<sales>235</sales>
</book>
<book>
<title>Sword of Honour</title>
<author>Evelyn Waugh</author>
<publisher>Penguin Books</publisher>
<isbn>0 14 018967 X</isbn>
<price>12.99</price>
<sales>12</sales>
</book>
<book>
<title>Angela's Ashes</title>
<author>Frank McCourt</author>
<publisher>HarperCollins</publisher>
<isbn>0 00 649840 X</isbn>
<price>6.99</price>
<sales>235</sales>
</book>
<book>
<title>Sword of Honour</title>
<author>Evelyn Waugh</author>
<publisher>Penguin Books</publisher>
<isbn>0 14 018967 X</isbn>
<price>12.99</price>
<sales>12</sales>
</book>
<book>
<title>Angela's Ashes</title>
<author>Frank McCourt</author>
<publisher>HarperCollins</publisher>
<isbn>0 00 649840 X</isbn>
<price>6.99</price>
<sales>235</sales>
</book>
<book>
<title>Sword of Honour</title>
<author>Evelyn Waugh</author>
<publisher>Penguin Books</publisher>
<isbn>0 14 018967 X</isbn>
<price>12.99</price>
<sales>12</sales>
</book>
<book>
<title>Angela's Ashes</title>
<author>Frank McCourt</author>
<publisher>HarperCollins</publisher>
<isbn>0 00 649840 X</isbn>
<price>6.99</price>
<sales>235</sales>
</book>
<book>
<title>Sword of Honour</title>
<author>Evelyn Waugh</author>
<publisher>Penguin Books</publisher>
<isbn>0 14 018967 X</isbn>
<price>12.99</price>
<sales>12</sales>
</book>
<book>
<title>Angela's Ashes</title>
<author>Frank McCourt</author>
<publisher>HarperCollins</publisher>
<isbn>0 00 649840 X</isbn>
<price>6.99</price>
<sales>235</sales>
</book>
<book>
<title>Sword of Honour</title>
<author>Evelyn Waugh</author>
<publisher>Penguin Books</publisher>
<isbn>0 14 018967 X</isbn>
<price>12.99</price>
<sales>12</sales>
</book>
<book>
<title>Angela's Ashes</title>
<author>Frank McCourt</author>
<publisher>HarperCollins</publisher>
<isbn>0 00 649840 X</isbn>
<price>6.99</price>
<sales>235</sales>
</book>
<book>
<title>Sword of Honour</title>
<author>Evelyn Waugh</author>
<publisher>Penguin Books</publisher>
<isbn>0 14 018967 X</isbn>
<price>12.99</price>
<sales>12</sales>
</book>
</booklist>
желаемый, правильный результат получается :
100 100 Angela's AshesFrank McCourtHarperCollins0 00 649840 X6.99235Sword of HonourEvelyn WaughPenguin Books
Объяснение:
Это похоже на:
f:foldl(f:add(), 0, 1 to 10)
вышеприведенное выражение вычисляет сумму чисел от 1 до 10:
Функция f:add()
передается в качестве первого параметра в f:foldl()
.
Второй параметр - это начальное накопленное значение - 0.
Третий параметр - это последовательность элементов, подлежащих обработке.
Функция foldl берет текущее накопленное значение и текущий заголовок последовательности (заголовок третьего аргумента) и применяет к ним функцию f:add()
.Результатом становится новое накопленное значение, а foldl () вызывает себя рекурсивно с тем же 1-м аргументом, новым накопленным значением и хвостом последовательности.
В решении выше накопленное значение представляет собой тройку, состоящую изограничение длины текста, суммарная длина и конкатенация накопленной строки.
Вместо f:add()
мы используем f:limitedConcat()
, который добавляет как длину строки, так и объединяет значение текущего текстового узла, если общее значениене будет превышать указанный общий текстовый лимит.