Subject: Re: [xsl] Formatting CDATA information From: Jeni Tennison <mail@xxxxxxxxxxxxxxxx> Date: Sat, 27 Jan 2001 12:00:43 +0000 |
Hi Tina, > The problem is that when this gets converted to HTML all of the line > breaks in the CDATA section are lost, and it becomes one long line. > Is there a way to format what's inside the CDATA tag to have <br> > after each line? Sure. The following template uses recursion to go through a string and substitute all the line breaks (
) with 'br' elements. (These are the default substitutions - you can substitute other things by passing different values for the $from and $to parameters.) <xsl:template name="substitute"> <xsl:param name="string" /> <xsl:param name="from" select="'
'" /> <xsl:param name="to"> <br /> </xsl:param> <xsl:choose> <xsl:when test="contains($string, $from)"> <xsl:value-of select="substring-before($string, $from)" /> <xsl:copy-of select="$to" /> <xsl:call-template name="substitute"> <xsl:with-param name="string" select="substring-after($string, $from)" /> <xsl:with-param name="from" select="$from" /> <xsl:with-param name="to" select="$to" /> </xsl:call-template> </xsl:when> <xsl:otherwise> <xsl:value-of select="$string" /> </xsl:otherwise> </xsl:choose> </xsl:template> So, for your example you can call the above template on the failure information using: <xsl:template match="failure"> <p>FAILURE INFO:</p> <xsl:call-template name="substitute"> <xsl:with-param name="string" select="." /> </xsl:call-template> </xsl:template> The other option, of course, is to use the HTML 'pre' element or to use the CSS white-space property set to 'pre' to tell the browser to take notice of the whitespace in the HTML that you're producing. These might be easier to handle than recursing through the string. I hope that helps, Jeni --- Jeni Tennison http://www.jenitennison.com/ XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
[xsl] Formatting CDATA information, Chan, Tina | Thread | [xsl] RE: XSL-FO -> RTF, Joshua Allen |
Re: [xsl] Getting the deepest node , Jeni Tennison | Date | RE: Microsoft XSLT command-line too, Julian F. Reschke |
Month |