2012-02-07 126 views
1

我在Firefox中遇到CDATA問題。除FF以外,每個瀏覽器都正確分析了<newsDesc>下的段落標記。但是,<strong><br/>標籤在任何瀏覽器中都不會被解析。我正在使用XSLT轉換jQuery插件。我已經包含了我的HTML,XML和XSL文件。CDATA在Firefox中無法正確解析

我一直在盯着這個問題的方式太久,我越來越無處可去。我做了很多研究,但沒有多大幫助。

任何建議將不勝感激。謝謝!

HTML

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" 
     "http://www.w3.org/TR/html4/loose.dtd"> 
<html> 
<head> 
    <title></title> 
</head> 
<body> 
<div id="pagecontent"></div> 
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script> 
<script type="text/javascript" src="http://daersystems.com/jquery/transform/js/jquery.transform.js"></script> 
<script> 
    $(function() { 
     $("#pagecontent").transform({xml: "test.xml", xsl: "test.xsl"}); 
    }); 
</script> 
</body> 
</html> 

XML

<?xml version="1.0" encoding="windows-1252"?> 

<news> 
    <newsRelease newsId="1341" category="PRD" subcategory="SPP"> 
     <region>NA</region> 
     <site>MCA</site> 
     <country>US</country> 
     <status>P</status> 
     <headline> 
      <![CDATA[Lorem Ipsum]]></headline> 
     <subHeadline> 
      <![CDATA[Lorem&trade; <br />This is a headline.]]></subHeadline> 
     <location><![CDATA[New York, NY]]></location> 
     <language>English</language> 
     <releaseDate>January 05, 2011</releaseDate> 
     <releaseDate2></releaseDate2> 
     <publishDate>01/05/2011</publishDate> 
     <encrptSw>N</encrptSw> 
     <newsDesc> 
      <![CDATA[ 
      <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Maecenas eu quam nulla. Morbi tellus leo, dignissim et euismod in, volutpat ut mi. Ut a pharetra odio. Mauris dui magna, eleifend eget pellentesque a, tempus eget mi. Praesent luctus, lorem at egestas rutrum, mi massa pulvinar enim, quis porttitor arcu felis non enim. Integer vel diam ac augue pretium gravida. Duis ut arcu a neque commodo sodales. Sed sit amet nisl arcu, eu pulvinar mauris. </p> 
<p>Curabitur at nisi nulla. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Aenean nisi erat, faucibus a posuere sed, blandit nec nisl. Fusce commodo vulputate tortor, at lacinia est porttitor et. Aliquam commodo nulla neque, nec fringilla felis. Sed sollicitudin aliquam mi, in egestas nunc suscipit sed. Donec sed odio massa, at auctor ipsum. Aenean vitae erat justo. Integer sed erat lectus, in faucibus dolor. </p> 
<p>Proin molestie hendrerit auctor. Sed in quam libero. Quisque justo quam, vulputate a bibendum in, laoreet vel tortor. Praesent vel eros mi, at semper dolor. Praesent quis tincidunt justo.</p> 
<p>Aenean varius, nisl quis tincidunt blandit, mi turpis laoreet ligula, at sagittis urna est ut sapien. Curabitur facilisis pharetra nisi quis imperdiet. Duis ac enim risus, in iaculis sapien. Fusce sit amet commodo felis. In eget nibh nisl, vel mollis magna. Praesent et velit quis erat suscipit malesuada.</p> 
<p>Vestibulum imperdiet, elit at aliquet ullamcorper, odio orci posuere erat, sed facilisis sapien ipsum quis est. Suspendisse id mollis velit. Aenean tincidunt volutpat lacus ut dapibus. In tellus neque, lacinia sit amet feugiat id, venenatis vel sem. Lorem ipsum dolor sit amet, consectetur adipiscing elit. </p> 
<p>For more on this feature, please visit: <br /> 
<a href="http://www.google.com">http://www.google.com</a></p> 
      ]]> 
     </newsDesc> 
     <footers> 
      <footer> 
       <id>1381</id> 
       <footerTxt> 
        <![CDATA[<strong>About this Service<br /></strong>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Maecenas eu quam nulla. Morbi tellus leo, dignissim et euismod in, volutpat ut mi. Ut a pharetra odio. Mauris dui magna, eleifend eget pellentesque a, tempus eget mi. Praesent luctus, lorem at egestas rutrum, mi massa pulvinar enim, quis porttitor arcu felis non enim. Integer vel diam ac augue pretium gravida. Duis ut arcu a neque commodo sodales. Sed sit amet nisl arcu, eu pulvinar mauris. For more information, go to <a href="http://www.google.com">www.google.com</a>]]></footerTxt> 
       <displayOrder>1</displayOrder> 
      </footer> 
      <footer> 
       <id>1382</id> 
       <footerTxt> 
        <![CDATA[<strong>About this Product<br /></strong>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Maecenas eu quam nulla. Morbi tellus leo, dignissim et euismod in, volutpat ut mi. Ut a pharetra odio. Mauris dui magna, eleifend eget pellentesque a, tempus eget mi. Praesent luctus, lorem at egestas rutrum, mi massa pulvinar enim, quis porttitor arcu felis non enim. Integer vel diam ac augue pretium gravida. Duis ut arcu a neque commodo sodales. Sed sit amet nisl arcu, eu pulvinar mauris. For more information, please visit us at <a href="http://www.google.com">www.google.com</a>. ]]></footerTxt> 
       <displayOrder>2</displayOrder> 
      </footer> 
     </footers> 
     <multimedia> 
      <images></images> 
      <videos></videos> 
      <podcasts></podcasts> 
      <documents></documents> 
     </multimedia> 
     <rss url=""/> 

    </newsRelease> 
</news> 

XSL

<?xml version="1.0" encoding="utf-8"?> 
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
       xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl"> 
    <xsl:output method="html" indent="yes" encoding="utf-8" omit-xml-declaration="yes" standalone="yes"/> 
    <xsl:output /> 
    <xsl:template match="/news"> 
     <xsl:variable name="pageTitle" select="newsRelease/seo/pageTitle"/> 
     <xsl:variable name="keywords" select="newsRelease/seo/keywords"/> 
     <xsl:variable name="description" select="newsRelease/seo/description"/> 
     <xsl:variable name="isImage" select="count(newsRelease/multimedia/images/image)"/> 
     <xsl:variable name="isDoc" select="count(newsRelease/multimedia/documents/document)"/> 
     <xsl:variable name="isIPOD" select="count(newsRelease/multimedia/podcasts/podcast)"/> 
     <xsl:variable name="isVideo" select="count(newsRelease/multimedia/videos/video)"/> 

     <h4 class="content-subtitle" style="width:250px;">Contacts</h4> 
     <xsl:for-each select="newsRelease/contacts/contact"> 
      <xsl:variable name="emailAddr" select="email" /> 
      <p><a style="font-size:11px; font-family: Arial, Verdana, Helvetica, sans-serif; color:#397984;" href="mailto:{$emailAddr}"><xsl:value-of select="name"/></a>,&#160;<xsl:value-of select="companyName"/>,&#160;<xsl:value-of select="phoneNumber" /></p> 
     </xsl:for-each> 


     <xsl:if test="$isDoc>0"> 
      <div class="info-box right"> 
       <h5>Related Information</h5> 
       <div id="info-padding"><strong>Document Download</strong></div> 
       <xsl:for-each select="newsRelease/multimedia/documents/document"> 
        <div id="info-padding"><img src="../images/download_img.jpg" height="14" width="14" border="0" /> <xsl:variable name="documentSrc" select="@src" /><a href="{$documentSrc}">&#160;download</a></div> 
       </xsl:for-each> 
      </div> 
     </xsl:if> 

     <div class="news-subtitle"><xsl:value-of select="newsRelease/headline" /></div> <br /> 
     <strong><em><xsl:value-of select="newsRelease/subHeadline" /></em></strong> 
     <p> </p> 
     <p><em><strong><xsl:value-of select="newsRelease/location"/>,&#160;<xsl:value-of select="newsRelease/releaseDate"/></strong> - </em> 
      <xsl:value-of select="newsRelease/newsDesc" disable-output-escaping="yes" /></p> 
     <xsl:for-each select="newsRelease/footers/footer"> 
      <p> <xsl:value-of select="footerTxt" /></p> 
     </xsl:for-each> 

    </xsl:template> 
</xsl:stylesheet> 

回答

3

Firefox不支持禁用鷗tput-escaping你嘗試使用,所以一般來說Firefox或Mozilla瀏覽器不可能實現這種方法。

+0

Firefox的另一種選擇是什麼? – 2012-02-07 16:43:35

+1

@ellenchristine:Firefox解決方法建議在這裏:https://bugzilla.mozilla.org/show_bug.cgi?id = 98168#c125(未經我測試)。 – mzjn 2012-02-07 18:32:04