RE: [xsl] Re: Fixed Line Length Output

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"
<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: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)"

This will set the line length to 72, but it doesn't put line breaks in a
pretty place. :)



-----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:

<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!


-----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
> 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"

 <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:template name="combineToLength">
    <xsl:param name="pmaxLength"/>
    <xsl:param name="pCurrString"/>
    <xsl:param name="pList" select="/.."/>

    <xsl:when test="$pList">
      <xsl:variable name="vMyString"
        <xsl:variable name="vMyList"
                 $pList[position() > 1][not($pCurrString)]"/>

          <xsl:when test="string-length($vMyString)
             <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:value-of select="concat($vMyString, '&#xA;')"/>
            <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:value-of select="$pCurrString"/>

when applied on your source.xml:

  <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>

produces the wanted result:

Andre Agassi,Boris Becker,Pat Cash
John McEnroe,Jimmy Connors
Stephan Edberg,Ivan Lendle


Dimitre Novatchev. -- the home of FXSL

 XSL-List info and archive:

 XSL-List info and archive:

Current Thread