could a line break be lost during parsing? 2003-01-17 - By Christopher Ebert
It sounds like the XML parsing is preserving the line breaks (which it should). You're probably losing them in the HTML formatting, which does not preserve line breaks. If you want the breaks, you'll have to translate them to <br> tags in HTML. Cheers, Chris
-----Original Message----- From: dongjiang tang [mailto:dtang@(protected)] Sent: Friday, January 17, 2003 9:44 AM To: xerces-j-user@(protected) Subject: could a line break be lost during parsing?
Hi, I am generating a html page using XSLT. I have a element with the value of mutiple line of text in a xml stream, like below: "line one line two line three" I print it out right before the parsing: System.out.println("XML = "+input.toString()) ; reader.parse(new InputSource(new StringReader(input.toString()))) ; I confirmed the element value is just like above with line break But in the html, I want to break it into mutiple line using the following templates but DID not see the line break: <xsl:template name="add-line-breaks"> <xsl:param name="string" select="." /> <xsl:choose> <xsl:when test="contains($string, '
')"> <xsl:value-of select="substring-before($string, '
')" /> <br /> <xsl:call-template name="add-line-breaks"> <xsl:with-param name="string" select="substring-after($string, '
')" /> </xsl:call-template> </xsl:when> <xsl:otherwise> <xsl:value-of select="$string" /> </xsl:otherwise> </xsl:choose> </xsl:template>
then I added some debuging code in my xsl file to show the element directly: <xsl:value-of select="@(protected)" /> (the @(protected) is the attribute holding that string value), then I went to the source after I re-generated the HTML page, I found that that element= "line one line two line three" without the line break I feel somehow I lost the line break during the parsing. Am I right about this? if yes, is there any confirguration to avoid this? thank you !! dongjiang
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <HTML><HEAD> <META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
<META content="MSHTML 6.00.2800.1126" name=GENERATOR> <STYLE></STYLE> </HEAD> <BODY bgColor=#ffffff> <DIV><FONT face=Arial color=#0000ff size=2></FONT> </DIV> <DIV><SPAN class=715245118-17012003><FONT face=Arial color=#0000ff size=2> It sounds like the XML parsing is preserving the line breaks (which it should). You're probably losing them in the HTML formatting, which does not preserve line breaks. If you want the breaks, you'll have to translate them to <br> tags in HTML.</FONT></SPAN></DIV> <DIV><SPAN class=715245118-17012003><FONT face=Arial color=#0000ff size=2></FONT></SPAN> </DIV> <DIV><SPAN class=715245118-17012003> <FONT face=Arial color=#0000ff size=2>Cheers,</FONT></SPAN></DIV> <DIV><SPAN class=715245118-17012003><FONT face=Arial color=#0000ff size=2></FONT></SPAN> </DIV> <DIV><SPAN class=715245118-17012003> <FONT face=Arial color=#0000ff size=2>Chris</FONT></SPAN></DIV> <DIV><SPAN class=715245118-17012003><FONT face=Arial color=#0000ff size=2></FONT></SPAN> </DIV> <BLOCKQUOTE dir=ltr style="MARGIN-RIGHT: 0px"> <DIV class=OutlookMessageHeader dir=ltr align=left><FONT face=Tahoma size=2>-----Original Message-----<BR><B>From:</B> dongjiang tang [mailto:dtang@(protected)]<BR><B>Sent:</B> Friday, January 17, 2003 9:44 AM<BR><B>To:</B> xerces-j-user@(protected)<BR><B>Subject:</B> could a line break be lost during parsing?<BR><BR></FONT></DIV> <DIV><FONT face=Arial size=2> <DIV><FONT face=Arial size=2>Hi, </FONT></DIV> <DIV><FONT face=Arial size=2>I am generating a html page using XSLT.</FONT></DIV> <DIV><FONT face=Arial size=2></FONT> </DIV> <DIV><FONT face=Arial size=2>I have a element with the value of mutiple line of text in a xml stream, like below:</FONT></DIV> <DIV><FONT face=Arial size=2>"line one</FONT></DIV> <DIV><FONT face=Arial size=2>line two</FONT></DIV> <DIV><FONT face=Arial size=2>line three"</FONT></DIV> <DIV><FONT face=Arial size=2>I print it out right before the parsing:</FONT></DIV> <DIV><FONT face=Arial size=2> System.out.println("XML = "+input.toString()) ;</FONT></DIV> <DIV><FONT face=Arial size=2> reader.parse(new InputSource(new StringReader(input.toString()))) ;</FONT></DIV> <DIV><FONT face=Arial size=2>I confirmed the element value is just like above with line break</FONT></DIV> <DIV><FONT face=Arial size=2></FONT> </DIV> <DIV><FONT face=Arial size=2>But in the html, I want to break it into mutiple line using the following templates but DID not see the line break:</FONT></DIV> <DIV><FONT face=Arial size=2><xsl:template name="add-line-breaks"><BR> <xsl:param name="string" select="." /><BR> <xsl:choose><BR> <xsl:when test="contains($string, '&#xA;')"><BR> <xsl:value-of select="substring-before($string, '&#xA;')" /><BR> <br /><BR> <xsl:call-template name="add-line-breaks"><BR>   ; <xsl:with-param name="string"<BR> select="substring-after($string, '&#xA;')" /><BR> </xsl:call-template><BR> </xsl:when><BR> <xsl:otherwise><BR> <xsl:value-of select="$string" /><BR> </xsl:otherwise><BR> </xsl:choose><BR></xsl:template><BR></DIV></FONT> <DIV><FONT face=Arial size=2>then I added some debuging code in my xsl file to show the element directly: <xsl:value-of select="@(protected)" /> (the @(protected) is the attribute holding that string value), then I went to the source after I re-generated the HTML page, I found that that element= "line one line two line three" without the line break</FONT></DIV> <DIV> </DIV> <DIV><FONT face=Arial size=2>I feel somehow I lost the line break during the parsing. </FONT></DIV> <DIV><FONT face=Arial size=2>Am I right about this? if yes, is there any confirguration to avoid this? </FONT></DIV> <DIV> </DIV> <DIV><FONT face=Arial size=2>thank you !!</FONT></DIV> <DIV> </DIV> <DIV><FONT face=Arial size=2>dongjiang</FONT> </DIV></FONT></DIV></BLOCKQUOTE></BODY></HTML>
|
|