[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Controlling Newlines (was Re: 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
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|