[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: Formatting CDATA information
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
|
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
|