2017-04-06 157 views
1

當我嘗試在Safari和Google加載時,當我嘗試在Firefox中加載我的xml以及空白頁時,出現此錯誤消息。我錯過了一個錯誤嗎? 我的造型要求:加載樣式表時出錯:解析XSLT樣式表失敗。

  • 年---大膽
  • 標題---- 900
  • 主任墨綠色深藍色字體粗細,大膽
  • 演員---蘭若男性,粉紅色的,如果女性
  • 類型----斜體和下劃線
  • 時間----暗紅色,加粗,下劃線

XML:

<?xml version="1.0" encoding="UTF-8"?> 
<?xml-stylesheet type="text/xsl" href="lab4_part2.xsl"?> 
<streaming> 
    <movies> 
     <year>1985</year> 
     <title>The Breakfast Club</title> 
     <director>John Hughes</director> 
     <actors> 
      <male>Emilio Estevez</male> 
      <male>Paul Gleason</male> 
      <male>Anthony Micheal Hall</male> 
      <male>Judd Nelson</male> 
      <female>Molly Ringwald</female> 
      <female>Ally Sheedy</female> 
     </actors> 
     <type>Comedy, Drama</type> 
     <time>97</time> 
    </movies> 
    <movies> 
     <year>1994</year> 
     <title>Forrest Gump</title> 
     <director>Robert Zemeckis</director> 
     <actors> 
      <male>Tom Hanks</male> 
      <male>Mykelti Williamson</male> 
      <male>Gary Sinise</male> 
      <male>Haley Joel Osment</male> 
      <female>Sally Field</female> 
      <female>Robin Wright</female> 
     </actors> 
     <type>Comedy, Drama, Romance</type> 
     <time>142</time> 
    </movies> 
</streaming> 

XSLT:

<?xml version="1.0"?> 

<xsl:stylesheet version="1.0" 
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> 

    <xsl:template match="/"> 
    <html> 
     <body> 
     <xsl:for-each select="streaming/movies"> 
      <div> 
      <p><xsl:value-of select="year" style="font-weight:bold;"/></p> 
      <p><xsl:value-of select="title" style="color:DarkBlue; font- 
weight:900;"/></p> 
      <p><xsl:value-of select="director" style="color:DarkGreen; font- 
weight:bold;"/></p> 
      <p>Actors</p> 
      <ul> 
       <xsl:for-each select="streaming/movies/actors"> 
       <xsl:if test="name() = 'male'"> 
        <li><xsl:value-of select="male" style="color:blue;"/></li> 
       </xsl:if> 
       <xsl:if test="name() = 'female'"> 
        <li><xsl:value-of select="male" style="color:pink;"/></li> 
       </xsl:if> 
       </xsl:for-each> 
      </ul> 
      <p><xsl:value-of select="type" style="text-decoration:underline; 
font-style:italic;"/></p> 
      <p><xsl:value-of select="time" style="color:DarkRed; text- 
decoration:underline; font-weight:bold;"/></p> 
      </div> 
     </xsl:for-each> 
     </body> 
    </html> 
    </xsl:template> 
</xsl:stylesheet> 
+0

您已被告知錯誤是什麼,但問題的根本原因是您正在運行此樣式表並且看不到錯誤消息。通常,在瀏覽器中運行XSLT並不是最好的開發環境,但大多數瀏覽器確實在開發人員控制檯中提供了診斷,並且您需要熟悉如何找到它們。 –

+0

我也推薦http://xsltransform.net/作爲測試您的XSLT的工具,但不幸的是,該服務暫時不可用... –

回答

3

xsl:value-of報表的一切似乎都對他們style屬性

<p> 
    <xsl:value-of select="year" style="font-weight:bold;"/> 
</p> 

style不在xsl:value-of有效的屬性。您應該將style屬性移動到您在所有情況下創建的html標籤上。例如

<p style="font-weight:bold;"> 
    <xsl:value-of select="year" /> 
</p> 
+0

哇,是的,你是如此的正確。愚蠢的錯誤。但是,我的演員仍然無法正確顯示。 – doopskunk

+0

這是一個與問題有關的單獨問題。但是因爲你在做'。此時你的上下文已經在'movies'節點上了,所以你所需要做的就是'' –

+0

實際上,你需要爲每個節點執行''獲取'actors'下的子節點,然後執行'輸出子節點的實際文本值。 –