This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

RE: Controlling Newlines (was Re: stripping newlines)



great,

i was able to fix it. i made sure my transforms had <xsl:output ...
indent="no"> and i'm using JDOM also, so initializing the XMLOutputter with
newlines="false" cut out all the unnecessary newlines.

thanks,
-matt

>-----Original Message-----
>From: Thomas B. Passin [mailto:tpassin@mitretek.org]
>Sent: Wednesday, September 05, 2001 12:19 PM
>To: xsl-list@lists.mulberrytech.com
>Subject: Controlling Newlines (was Re: [xsl] stripping newlines)
>
>
>[Matt Alexander]
>
>> i'm creating an html page with javascript in it.
>>
>> inside one of the js calls, setHTML('') i can't have any 
>carriage returns,
>> or it is an 'unterminated string'.
>> the only way i've been able to get around this is to right 
>my transform as
>> one big chunk of xslt w/out any carriage returns. this makes 
>it ugly and
>> hard to update, so i'm, hoping to find a transform that would take my
>> transform and create a new transform without any carriage 
>return between
>> elements.  xsl:strip-space, never catches all of the returns.
>
>If you think of this as a javascript problem, you can come up with any
>number of ways to deal with it.  For example, take this XML document:
>
><root>
> <row><cell>A1</cell><cell>A2</cell></row>
> <row><cell>B1</cell><cell>B2</cell></row>
></root>
>
>Here's a stylesheet to write the javascript:
>
><?xml version="1.0"?>
><xsl:stylesheet version="1.0"
>xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>
>
><xsl:template match='/root'>
>var str='<table>'
><xsl:apply-templates select="row"/>
>str+='</table>'
>blah.setHTML(str)
></xsl:template>
>
><xsl:template match='row'>
>    str+='<tr>'<xsl:apply-templates select="cell"/>
>    str+='</tr>'
></xsl:template>
>
><xsl:template match='cell'>
> str+='<td><xsl:value-of select='.'/></td>'
></xsl:template>
>
></xsl:stylesheet>
>
>Here is the result using Saxon in XML Cooktop (including all the line
>breaks):
>
><?xml version="1.0" encoding="utf-8"?>
>var str='<table>'
>
>    str+='<tr>'
> str+='<td>A1</td>'
>
> str+='<td>A2</td>'
>
>    str+='</tr>'
>
>    str+='<tr>'
> str+='<td>B1</td>'
>
> str+='<td>B2</td>'
>
>    str+='</tr>'
>
>str+='</table>'
>blah.setHTML(str)
>
>
>This is in addition to any other things you end up doing to 
>control line
>breaks.  Line breaks may turn out differently depending on 
>which processor
>you use (and possibly how it's configured).  I'm never too sure about
>exactly what's going to happen.  For example, from within XML Cooktop,
>outputting text like this, I usually get blank lines between 
>output strings
>with msxml3 whereas with Saxon I don't.  So I have several 
>tricks that I
>try, and I can usually get what I want, but sometimes they make the
>stylesheet less readable.
>
>The root cause of all this is the handling of whitespace-only 
>nodes, as I
>understand it.  When do you have one, and should the processor 
>output it or
>not?
>
>I can get output without the extra lines, looking like this:
>
><?xml version="1.0" encoding="utf-8"?>
>var str='<table>'
>    str+='<tr>'
> str+='<td>A1</td>'
> str+='<td>A2</td>'
>    str+='</tr>'
>    str+='<tr>'
> str+='<td>B1</td>'
> str+='<td>B2</td>'
>    str+='</tr>'
>str+='</table>'
>blah.setHTML(str)
>
>To get this, I changed the stylesheet to put the 
></xsl:template> tags on the
>same line as the last line of the template body:
>
><?xml version="1.0"?>
><xsl:stylesheet version="1.0"
>xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>
>
><xsl:template match='/root'>
>var str='<table>'<xsl:apply-templates select="row"/>
>str+='</table>'
>blah.setHTML(str)
></xsl:template>
>
><xsl:template match='row'>
>    str+='<tr>'<xsl:apply-templates select="cell"/>
>    str+='</tr>'</xsl:template>
>
><xsl:template match='cell'>
> str+='<td><xsl:value-of select='.'/></td>'</xsl:template>
>
></xsl:stylesheet>
>
>However, using msxml3 with this stylesheet, again in XML 
>Cooktop, I get a
>blank line between each line of text.  Notice that this 
>wouldn't stop the
>javascript code from working, when you organize it this way.
>
>Long-windedly-yours,
>
>Tom P
>
>>
>> i need...
>> blah.setHTML('<table><tr><td><etc..../></td></tr></table>');
>>
>> but i always end up with...
>>
>> blah.setHTML('<table><tr>
>> <td><etc..../></td>
>> </tr></table>');
>>
>> or something like that. i don't know if there is anything 
>that will do
>this
>> in xslt, but i'd appreciate any help...
>
>
>
> XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
>

 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]