Use the FXSL stylesheet file:
strSplit-to-Lines.xsl
And modify it appropriately for your case.
This transformation (just modified the above stylesheet, calling the
template with lineLength=16):
<xsl:styleshe et version="2.0"
xmlns:xsl="http ://www.w3.org/1999/XSL/Transform"
xmlns:f="http://fxsl.sf.net/"
xmlns:str-split2lines-func="f:str-split2lines-func"
exclude-result-prefixes="f str-split2lines-func"
>
<xsl:import href="str-foldl.xsl"/>
<!-- to be applied on text.xml -->
<str-split2lines-func:str-split2lines-func/>
<xsl:output indent="yes" omit-xml-declaration="ye s"/>
<xsl:template match="/">
<xsl:call-template name="str-split-to-lines">
<xsl:with-param name="pStr"
select="concat( normalize-space(/), ' ')"/>
<xsl:with-param name="pLineLeng th" select="16"/>
<xsl:with-param name="pDelimite rs" select="'
'"/>
</xsl:call-template>
</xsl:template>
<xsl:template name="str-split-to-lines">
<xsl:param name="pStr"/>
<xsl:param name="pLineLeng th" select="60"/>
<xsl:param name="pDelimite rs" select="'
'"/>
<xsl:variable name="vsplit2li nesFun"
select="documen t('')/*/str-split2lines-func:*[1]"/>
<xsl:variable name="vrtfParam s">
<delimiters><xs l:value-of select="$pDelim iters"/></delimiters>
<lineLength><xs l:copy-of select="$pLineL ength"/></lineLength>
</xsl:variable>
<xsl:variable name="vResult">
<xsl:call-template name="str-foldl">
<xsl:with-param name="pFunc" select="$vsplit 2linesFun"/>
<xsl:with-param name="pStr" select="$pStr"/>
<xsl:with-param name="pA0" select="$vrtfPa rams"/>
</xsl:call-template>
</xsl:variable>
<xsl:for-each select="$vResul t/line">
<xsl:for-each select="word">
<xsl:value-of select="concat( ., ' ')"/>
</xsl:for-each>
<xsl:value-of select="'
'"/>
</xsl:for-each>
</xsl:template>
<xsl:template match="str-split2lines-func:*" mode="f:FXSL">
<xsl:param name="arg1" select="/.."/>
<xsl:param name="arg2"/>
<xsl:copy-of select="$arg1/*[position() < 3]"/>
<xsl:copy-of select="$arg1/line[position() != last()]"/>
<xsl:choose>
<xsl:when test="contains( $arg1/*[1], $arg2)">
<xsl:if test="string($a rg1/word)">
<xsl:call-template name="fillLine" >
<xsl:with-param name="pLine" select="$arg1/line[last()]"/>
<xsl:with-param name="pWord" select="$arg1/word"/>
<xsl:with-param name="pLineLeng th" select="$arg1/*[2]"/>
</xsl:call-template>
</xsl:if>
</xsl:when>
<xsl:otherwis e>
<xsl:copy-of select="$arg1/line[last()]"/>
<word><xsl:valu e-of select="concat( $arg1/word, $arg2)"/></word>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<!-- Test if the new word fits into the last line -->
<xsl:template name="fillLine" >
<xsl:param name="pLine" select="/.."/>
<xsl:param name="pWord" select="/.."/>
<xsl:param name="pLineLeng th" />
<xsl:variable name="vnWordsIn Line" select="count($ pLine/word)"/>
<xsl:variable name="vLineLeng th" select="string-length($pLine) +
$vnWordsInLine"/>
<xsl:choose>
<xsl:when test="not($vLin eLength + string-length($pWord) >
$pLineLength)">
<line>
<xsl:copy-of select="$pLine/*"/>
<xsl:copy-of select="$pWord"/>
</line>
</xsl:when>
<xsl:otherwis e>
<xsl:copy-of select="$pLine"/>
<line>
<xsl:copy-of select="$pWord"/>
</line>
<word/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>
Produces the wanted results (the lines are truncated but padding each line
to 16 chars width is left as an exercise to the reader :o) )
AAA BBBBBBBBBBB
CCCCCCCCC
DDDDDDDDDDDDDDD
EEEEE FF G
Cheers,
Dimitre Novatchev.
<ol************ **@algosyn.comw rote in message
news:11******** **************@ v33g2000cwv.goo glegroups.com.. .
Hello,
>>From the source file, I need to create with XSLT a result file with
the following constraints:
source:
<Source>
<Item>AAA</Item>
<Item>BBBBBBBBB BB</Item>
<Item>CCCCCCCCC </Item>
<Item>DDDDDDDDD DDDDDD</Item>
<Item>EEEEE</Item>
<Item>FF</Item>
<Item>G</Item>
</Source>
result: (text file with line length = 16, with spaces)
AAA BBBBBBBBBBB
CCCCCCCCC
DDDDDDDDDDDDDDD
EEEEE FF G
Each line of the output file is composed of Item texts separated by
one space.
If by adding a new item text on the line we have more than 16
characters then pad the current line with spaces and copy the item
text to a new line.
I do not know if it is possible to do that in XSLT.
Thanks for your help.
Olivier