[XSL-LIST Mailing List Archive Home]
[By Thread]
[By Date]
RE: [xsl] Fixed Line Length Output
Subject: RE: [xsl] Fixed Line Length Output From: "Cynthia DeLaria" <cdelaria@xxxxxxxxx> Date: Tue, 9 Dec 2003 15:05:16 -0700 |
Here it is, done with 1/3 of the code, no imported stylesheets, and without relying on FXSL (which I do not have available on my production environments). Cynthia <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output method="html" indent="no" encoding="UTF-8" /> <xsl:template match="/"> <xsl:for-each select="bb_template/new_releases/release"> <xsl:call-template name="breakLength"> <xsl:with-param name="maxLength" select="72" /> <xsl:with-param name="copy" select="description" /> </xsl:call-template><br /> <br /> </xsl:for-each> </xsl:template> <xsl:template name="breakLength"> <xsl:param name="maxLength" /> <xsl:param name="copy" /> <xsl:param name="current" /> <xsl:choose> <xsl:when test="$copy"> <xsl:variable name="nextWord"> <xsl:choose> <xsl:when test="contains($copy,' ')"> <xsl:value-of select="substring-before($copy,' ')" /> </xsl:when> <xsl:otherwise> <xsl:value-of select="$copy" /> </xsl:otherwise> </xsl:choose> </xsl:variable> <xsl:choose> <xsl:when test="string-length($current)+1+string-length($nextWord)<$maxLength"> <xsl:call-template name="breakLength"> <xsl:with-param name="maxLength" select="$maxLength" /> <xsl:with-param name="copy" select="substring-after($copy,' ')" /> <xsl:with-param name="current" select="concat($current,' ',$nextWord)" /> </xsl:call-template> </xsl:when> <xsl:otherwise> <xsl:value-of select="$current" /><br /> <xsl:call-template name="breakLength"> <xsl:with-param name="maxLength" select="$maxLength" /> <xsl:with-param name="copy" select="$copy" /> <xsl:with-param name="current" /> </xsl:call-template> </xsl:otherwise> </xsl:choose> </xsl:when> <xsl:otherwise> <xsl:value-of select="$current" /><br /> </xsl:otherwise> </xsl:choose> </xsl:template> </xsl:stylesheet> -----Original Message----- From: Dimitre Novatchev [mailto:dnovatchev@xxxxxxxxx] Sent: Tuesday, December 09, 2003 1:07 PM To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx Subject: [xsl] Re: Re: Re: Fixed Line Length Output Cynthia, "Cynthia DeLaria" <cdelaria@xxxxxxxxx> wrote in message news:CE54CE22EF3A65438885197A240E408BC576DE@xxxxxxxxxxxxxxxxxxx > Thanks. Though this is already where I was, except that you simply cut > off the lines and got rid of the rest of the content. Not exactly... Do notice that the lines are now maximum 64 characters long... You can change this to any number you like by setting the value of the corresponding xsl:param. And I think this was what you wanted -- in case you'd wanted something else you didn't express it in your message... > And whatever file > you're importing here is not included anywhere. I said clearly that this code was using templates from FXSL. Here's the template you didn't find -- now you'll be able to perform the transformation: <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:ext="http://exslt.org/common" > <xsl:template name="dvc-str-foldl"> <xsl:param name="pFunc" select="/.."/> <xsl:param name="pA0"/> <xsl:param name="pStr"/> <xsl:choose> <xsl:when test="not($pStr)"> <xsl:copy-of select="$pA0"/> </xsl:when> <xsl:otherwise> <xsl:variable name="vcntList" select="string-length($pStr)"/> <xsl:choose> <xsl:when test="$vcntList = 1"> <xsl:apply-templates select="$pFunc[1]"> <xsl:with-param name="arg0" select="$pFunc[position() > 1]"/> <xsl:with-param name="arg1" select="$pA0"/> <xsl:with-param name="arg2" select="substring($pStr,1,1)"/> </xsl:apply-templates> </xsl:when> <xsl:otherwise> <xsl:variable name="vHalfLen" select="floor($vcntList div 2)"/> <xsl:variable name="vFunResult1"> <xsl:call-template name="dvc-str-foldl"> <xsl:with-param name="pFunc" select="$pFunc"/> <xsl:with-param name="pA0" select="$pA0"/> <xsl:with-param name="pStr" select="substring($pStr, 1, $vHalfLen )"/> </xsl:call-template> </xsl:variable> <xsl:call-template name="dvc-str-foldl"> <xsl:with-param name="pFunc" select="$pFunc"/> <xsl:with-param name="pStr" select="substring($pStr,$vHalfLen+1)" /> <xsl:with-param name="pA0" select="ext:node-set($vFunResult1)"/> </xsl:call-template> </xsl:otherwise> </xsl:choose> </xsl:otherwise> </xsl:choose> </xsl:template> </xsl:stylesheet> ===== Cheers, Dimitre Novatchev. http://fxsl.sourceforge.net/ -- the home of FXSL XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
RE: [xsl] Fixed Line Length Output, Jarno . Elovirta | Thread | [xsl] Re: Fixed Line Length Output, Dimitre Novatchev |
[xsl] tail recursion?, David Tolpin | Date | RE: [xsl] Converting to uppercase, Todd Baker |
Month |