Closed
Bug 258395
Opened 20 years ago
Closed 20 years ago
Doesn't transform XML to HTML properly when CDATA is used to add HTML tags
Categories
(Core :: XSLT, defect)
Tracking
()
People
(Reporter: ayalewk, Assigned: peterv)
Details
Attachments
(2 files)
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.6) Gecko/20040113 Build Identifier: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.6) Gecko/20040113 Transform the following XML with given XSL (open the XML with Mozilla 1.6 - (Windows; U; Windows NT 5.0; en-US; rv:1.6) Gecko/20040113): XML: <?xml version="1.0" encoding="UTF-8"?> <?xml-stylesheet type="text/xsl" href="xsl.xsl"?> <poem> <verse> -Seest thou yon dreary Plain, forlorn and wild, -Seest thou yon dreary Plain, forlorn and wild, </verse> </poem> XSL: <?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output indent="yes" encoding="UTF-8"/> <xsl:template match="/"> <HTML> <BODY> <xsl:apply-templates/> </BODY> </HTML> </xsl:template> <xsl:template match="verse"> <p> <xsl:call-template name="InsertLineBreaks"> <xsl:with-param name="string" select="."/> <!-- previous_index is the number of dashes the previous line has. In this case there is no previous line therefore we pass 0 as the number of dashes for the previous string, so that if the next line has dashes the 'ordered bullet list' HTML tag can be opened --> <xsl:with-param name="previous_index" select="0"/> </xsl:call-template> </p> </xsl:template> <xsl:template name="InsertLineBreaks"> <xsl:param name="string"/> <xsl:param name="previous_index"/> <xsl:if test="normalize-space($string)"> <!-- index is the number of dashes this line has. In case this line is empty we assign index equal to the previous_index, because empty lines are ignored --> <xsl:variable name="index"> <xsl:choose> <xsl:when test="not(contains($string, '
')) or (string-length(normalize-space(substring-before($string, '
'))) > 0)"> <xsl:value-of select="string-length(substring-before($string, substring(normalize-space(translate($string,'-',' ')), 1, 1))) - string-length(substring-before($string, substring(normalize-space($string), 1, 1)))"/> </xsl:when> <xsl:otherwise> <xsl:value-of select="$previous_index"/> </xsl:otherwise> </xsl:choose> </xsl:variable> <xsl:choose> <xsl:when test="contains($string, '
')"> <xsl:choose> <!-- If the string starts with a line-feed, do nothing --> <xsl:when test="starts-with($string, '
')"/> <xsl:otherwise> <!-- Output the substring before the first line-feed --> <xsl:call-template name="trimDash"> <xsl:with-param name="string" select="normalize-space(substring-before($string, '
'))"/> <xsl:with-param name="index" select="$index"/> <xsl:with-param name="previous_index" select="$previous_index"/> <!-- len is the normalized string length after the line break. If the string length is less than 0 we want we should close the 'ordered bullet list' HTML tag --> <xsl:with-param name="len" select="string-length(normalize-space(substring-after($string, '
')))"/> </xsl:call-template> </xsl:otherwise> </xsl:choose> <!-- Call this template again --> <xsl:call-template name="InsertLineBreaks"> <!-- The rest of the string, i.e. the substring after the first line-feed --> <xsl:with-param name="string" select="substring-after($string,'
')"/> <xsl:with-param name="previous_index" select="$index"/> </xsl:call-template> </xsl:when> <xsl:otherwise> <!-- Output the substring before the first line-feed --> <xsl:call-template name="trimDash"> <xsl:with-param name="string" select="normalize-space($string)"/> <xsl:with-param name="index" select="$index"/> <xsl:with-param name="previous_index" select="$previous_index"/> <!-- len is the normalized string length after the line break. If the string length is less than 0 we want we should close the 'ordered bullet list' HTML tag --> <xsl:with-param name="len" select="string-length(normalize-space(substring-after($string, '
')))"/> </xsl:call-template> </xsl:otherwise> </xsl:choose> </xsl:if> </xsl:template> <xsl:template name="trimDash"> <xsl:param name="string"/> <xsl:param name="previous_index"/> <xsl:param name="index"/> <xsl:param name="len"/> <xsl:choose> <xsl:when test="starts-with($string, '-')"> <xsl:call-template name="trimDash"> <xsl:with-param name="string" select="substring($string, 2)"/> <xsl:with-param name="index" select="$index"/> <xsl:with-param name="previous_index" select="$previous_index"/> <xsl:with-param name="len" select="$len"/> </xsl:call-template> </xsl:when> <xsl:otherwise> <xsl:if test="$index - $previous_index > 0"> <xsl:call-template name="openUL"> <xsl:with-param name="count" select="$index - $previous_index"/> </xsl:call-template> </xsl:if> <xsl:if test="$index - $previous_index < 0"> <xsl:call-template name="closeUL"> <xsl:with-param name="count" select="$previous_index - $index"/> </xsl:call-template> </xsl:if> <xsl:choose> <xsl:when test="$index = 0"> <xsl:value-of select="$string"/> <BR/> </xsl:when> <xsl:otherwise> <LI> <xsl:value-of select="$string"/> </LI> </xsl:otherwise> </xsl:choose> <xsl:if test="$len = 0"> <xsl:call-template name="closeUL"> <xsl:with-param name="count" select="$index"/> </xsl:call-template> </xsl:if> <!-- Insert a line-feed to make it look pretty --> <xsl:text>
</xsl:text> </xsl:otherwise> </xsl:choose> </xsl:template> <xsl:template name="openUL"> <xsl:param name="count"/> <xsl:if test="$count > 0"> <xsl:text disable-output-escaping="yes"><![CDATA[<UL>]]></xsl:text> <!-- Insert a line-feed to make it look pretty --> <xsl:text>
</xsl:text> <xsl:call-template name="openUL"> <xsl:with-param name="count" select="$count - 1"/> </xsl:call-template> </xsl:if> </xsl:template> <xsl:template name="closeUL"> <xsl:param name="count"/> <xsl:if test="$count > 0"> <xsl:text disable-output-escaping="yes"><![CDATA[</UL>]]></xsl:text> <!-- Insert a line-feed to make it look pretty --> <xsl:text>
</xsl:text> <xsl:call-template name="closeUL"> <xsl:with-param name="count" select="$count - 1"/> </xsl:call-template> </xsl:if> </xsl:template> </xsl:stylesheet> Reproducible: Always Steps to Reproduce: 1. See details 2. 3. Actual Results: I see the following in Mozilla browser: <UL> Seest thou yon dreary Plain, forlorn and wild, Seest thou yon dreary Plain, forlorn and wild, </UL> Expected Results: Bulleted list like this: . Seest thou yon dreary Plain, forlorn and wild, . Seest thou yon dreary Plain, forlorn and wild,
Comment 1•20 years ago
|
||
We are not going to work on this without an appropriate testcase, see http://www.mozilla.org/projects/xslt/bug-reporting.html
Comment 2•20 years ago
|
||
Chances are this is the "IE actually serializes and reparses the output instead of converting directly between DOMs" issue. And if its serializer is buggy, it won't escape things right and you'll end up parsing the "<ul>" string which that template is inserting as literal CDATA....
(Ayalew) I get comments that this may have worked in IE and not in Mozilla. But I have tested it with not only in IE, but also jdk 1.4 and Apache XSL processors and the out put is a good HTML file. The mozilla parser however fails to generate the HTML when CDATA is used to add HTML tags.
Comment 6•20 years ago
|
||
<xsl:text disable-output-escaping="yes"> is not supported. *** This bug has been marked as a duplicate of 98168 ***
Status: UNCONFIRMED → RESOLVED
Closed: 20 years ago
Resolution: --- → DUPLICATE
You need to log in
before you can comment on or make changes to this bug.
Description
•