could a line break be lost during parsing? 2003-01-17 - By dongjiang tang
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.1106" name=GENERATOR> <STYLE></STYLE> </HEAD> <BODY bgColor=#ffffff> <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></BODY></HTML>
|
|