Subject: RE: [xsl] Re: Fixed Line Length Output From: "Cynthia DeLaria" <cdelaria@xxxxxxxxx> Date: Mon, 8 Dec 2003 16:54:01 -0700 |
Forgot to include XSL that I am currently using: <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output method="html"/> <xsl:template match="/"> <xsl:for-each select="bb_template/new_releases/release"> <xsl:call-template name="breakLength"> <xsl:with-param name="maxLength" select="35" /> <xsl:with-param name="copy" select="description" /> </xsl:call-template> </xsl:for-each> </xsl:template> <xsl:template name="breakLength"> <xsl:param name="maxLength" /> <xsl:param name="copy" /> <xsl:value-of select="substring($copy,1,72)" /><br /> <xsl:call-template name="breakLength"> <xsl:with-param name="maxLength" select="$maxLength" /> <xsl:with-param name="copy" select="substring($copy,73)" /> </xsl:call-template> </xsl:template> </xsl:stylesheet> This will set the line length to 72, but it doesn't put line breaks in a pretty place. :) Thanks! Cynthia -----Original Message----- From: Cynthia DeLaria Sent: Monday, December 08, 2003 4:42 PM To: 'xsl-list@xxxxxxxxxxxxxxxxxxxxxx' Subject: RE: [xsl] Re: Fixed Line Length Output Hello, all. Thank you for tackling this subject. I have been wrestling with this same thing as I have a templating system that generates text e-mail messages where the line length can be no more than 72 characters. This example has opened up some interesting options as far as how to do that with certain pieces... However, this example assumes that the information gotten from a node is never going to be longer than 25 characters (or whatever the desired length is). In my case I have movie descriptions that are often times 300-400 characters in length, and I need to put line-breaks every 72 characters (or where it makes sense to do so). Is there any way to account for this? Here is example xml: <movieDesc> <description>They were betrayed by one of their own. Now the next heist isn't just about money - it's about payback.</description> <description>One's an amateur real estate broker. The other's a yoga instructor. Believe it or not, they're also two of LA's finest detectives!</description> <description>The mild-mannered Jerry has second thoughts about his daughter's wedding when he meets the groom's outrageous father!</description> <description>Return to the swinging sixties with Renee Zellweger and Ewan McGregor as they engage in a stylish battle of the sexes.</description> <description>When Willard decides it's time for revenge, his loyal, furry friends become his own personal army.</description> <description>Young friends lost deep in the Appalachian hills race to find civilization as they're pursued by horrors beyond their imagination.</description> <description>Two girls must wade through the emotional debris that clutters their lives after a tragic event brings them together.</description> </movieDesc> Thanks for any input! Cynthia -----Original Message----- From: Dimitre Novatchev [mailto:dnovatchev@xxxxxxxxx] Sent: Monday, December 08, 2003 2:27 PM To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx Subject: [xsl] Re: Fixed Line Length Output "Ali Afif Mutlu" <ali.mutlu@xxxxxxxxxxxx> wrote in message news:005001c3bdb1$f6eb4260$8928020a@xxxxxxxxxxxxx > Hi, > > >> can you please explain the sentence -- > >> *I want to regroup my items into fixed length of lines* > > Assume that the following list is the veteran tenis players of our > club > > <item>Andre Agassi</item> > <item>Boris Becker</item> > <item>Pat Cash</item> > <item>John McEnroe</item> > <item>Jimmy Connors</item> > <item>Stephan Edberg</item> > <item>Ivan Lendle</item> > > I want to display these names on a board where I can fit only 25 > characters on a roe, so on my board The list should be as follows (I > am not allowed to split first names and last names) > > Andre Agassi,Boris Becker > Pat Cash,John McEnroe,Jimmy Connors > Stephan Edberg,Ivan Lendle This transformation: <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output method="text"/> <xsl:template match="/"> <xsl:call-template name="combineToLength"> <xsl:with-param name="pmaxLength" select="35"/> <xsl:with-param name="pList" select="*/item"/> </xsl:call-template> </xsl:template> <xsl:template name="combineToLength"> <xsl:param name="pmaxLength"/> <xsl:param name="pCurrString"/> <xsl:param name="pList" select="/.."/> <xsl:choose> <xsl:when test="$pList"> <xsl:variable name="vMyString" select="concat($pCurrString, $pList[1][not($pCurrString)] )"/> <xsl:variable name="vMyList" select="$pList[$pCurrString] | $pList[position() > 1][not($pCurrString)]"/> <xsl:choose> <xsl:when test="string-length($vMyString) +1+string-length($vMyList[1]) <= $pmaxLength"> <xsl:call-template name="combineToLength"> <xsl:with-param name="pmaxLength" select="$pmaxLength"/> <xsl:with-param name="pCurrString" select="concat($vMyString, ',', $vMyList[1])"/> <xsl:with-param name="pList" select="$vMyList[position() > 1]"/> </xsl:call-template> </xsl:when> <xsl:otherwise> <xsl:value-of select="concat($vMyString, '
')"/> <xsl:call-template name="combineToLength"> <xsl:with-param name="pmaxLength" select="$pmaxLength"/> <xsl:with-param name="pCurrString" select="''"/> <xsl:with-param name="pList" select="$vMyList"/> </xsl:call-template> </xsl:otherwise> </xsl:choose> </xsl:when> <xsl:otherwise> <xsl:value-of select="$pCurrString"/> </xsl:otherwise> </xsl:choose> </xsl:template> </xsl:stylesheet> when applied on your source.xml: <players> <item>Andre Agassi</item> <item>Boris Becker</item> <item>Pat Cash</item> <item>John McEnroe</item> <item>Jimmy Connors</item> <item>Stephan Edberg</item> <item>Ivan Lendle</item> </players> produces the wanted result: Andre Agassi,Boris Becker,Pat Cash John McEnroe,Jimmy Connors Stephan Edberg,Ivan Lendle ===== 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 -> |
---|---|---|
[xsl] Re: Re: Fixed Line Length Out, Dimitre Novatchev | Thread | RE: [xsl] Re: Fixed Line Length Out, David . Pawson |
[xsl] Nested xsl:sort problems, Fred Wells | Date | RE: [xsl] Nested xsl:sort problems, Todd Baker |
Month |