2012-03-13 47 views
1

對不起,如果這看起來很荒謬我真的在這裏嘗試,但我沒有抓住這個xml類我在這裏。請看看並指出我在正確的方向,或者如果你至少可以帶我出深結xsl不會工作

這裏是XML部分

<?xml-stylesheet type="text/xsl" href="sci.xsl" ?> 
<rss version="2.0" 
    xmlns:dc="http://purl.org/dc/elements/1.1/" 

        xmlns:sy="http://purl.org/rss/1.0/modules/syndication/" 

        xmlns:admin="http://webns.net/mvcb/" 

        xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"> 



<channel> 
    <title>SciTimes News</title> 
    <link>home.htm</link> 

    <description>SciTimes delivers up-to-the-minute news and information on 
    the latest stories from the world of science and technology.</description> 

    <dc:language>en-us</dc:language> 

<dc:date>2008-03-24T12:22:54+09:00</dc:date> 

<sy:updatePeriod>hourly</sy:updatePeriod> 

    <sy:updateFrequency>1</sy:updateFrequency> 

    <sy:updateBase>2000-01-01T12:00+00:00</sy:updateBase> 


    <image> 
     <title>SciTimes.com</title> 
     <link>home.htm</link> 
     <url>scitimes.jpg</url> 
     <width>620</width> 
     <height>96</height> 
     <description>SciTimes delivers up-to-the-minute news and information on 
     the latest stories from the world of science and technology. 
     </description> 
    </image> 

    <item> 
     <title>Visual Memory</title> 
     <link>vm.htm</link> 
     <description>BOULDER, Colorado - The ability to retain memory about the 
     details of a natural scene is unaffected by the distraction of another 
     activity and this information is retained in "working memory" according 
     to researchers at the University of Colorado School of Medicine. These 
     results reinforce the notion that humans maintain useful information about 
     previous fixations in long-term working memory rather than the 
     limited capacity of visual short-term memory (VSTM). 
     </description> 
     <dc:pubDate>Mon, 24 Mar 2008 12:17:37 EST</dc:pubDate> 
     <dc:subject>Biology</dc:subject> 

    </item> 

    <item> 
     <title>Neptune probe launches</title> 
     <link>neptune.htm</link> 
     <description>CAPE CANAVERAL, Florida - The fastest spacecraft ever launched 
     began the first full day of its 2-billion mile journey to Neptune, where it 
     will study the gas giant and provide close-up images of its rings. The Neptune 5 
     spacecraft blasted off aboard an Atlas V rocket Sunday evening in a spectacular 
     start to the $900 million mission. The spacecraft can reach 38,000 mph, taking 6 
     years to reach Neptune and the outer reaches of the Solar System. 
     </description> 
     <dc:pubDate>Mon, 24 Mar 2008 12:11:44 EST</dc:pubDate> 
     <dc:subject>Space</dc:subject> 

    </item> 

    <item> 
     <title>Whale numbers in decline</title> 
     <link>whales.htm</link> 
     <description>ANCHORAGE, Alaska - A survey of beluga whales in Cook Inlet finds 
     that their numbers remain stagnant and could be declining despite efforts to get 
     the white whale population to rebound. Biologists with the NOAA conducted an aerial 
     survey southwest of Anchorage early last summer to count the belugas. An analysis 
     of the survey data indicates there were an estimated 324 beluga whales in Cook Inlet 
     in 2007, down from 376 the year before. 
     </description> 
     <dc:pubDate>Mon, 24 Mar 2008 12:05:12 EST</dc:pubDate> 
     <dc:subject>Biology</dc:subject> 

    </item> 

    <item> 
     <title>Satellite goes silent</title> 
     <link>nasa.htm</link> 
     <description>LOS ANGELES, California - A NASA satellite studying the Earth's Van 
     Allen Belt has stopped operating after three years, the space agency announced 
     over the weekend. The satellite, launched in 2004, successfully completed its 
     two-year primary mission, according to a NASA news release. It made observations 
     until last month when engineers discovered that its power supply had failed. 
     </description> 
     <dc:pubDate>Mon, 24 Mar 2008 12:03:31 EST</dc:pubDate> 
     <dc:subject>Space</dc:subject> 

    </item> 

</channel> 
</rss> 

這裏是XSLT

<?xml version="1.0" encoding="UTF-8" ?> 
<xsl:stylesheet 
    xmlns:xsl= "http://www.w3.org/1999/XSL/Transform" 
     xmlns:rss="http://purl.org/rss/1.0/" version="1.0" 
     xmlns:dc="http://purl.org/dc/elements/1.1/" 
     exclude-result-prefixes="rss dc"> 
    <xsl:output method="html" version="4.0"/> 

    <xsl:template match="/"> 
    <html> 
     <head> 
      <title><xsl:value-of select="channel/title"/></title> 
      <link rel="stylesheet" href="sci.css" type="text/css"/> 
     </head> 
     <body>  
     <div id="logo"><xsl:apply-templates select="image"/></div> 
     <div id="datetime"><xsl:value-of select="./dc:date"/>date</div> 

     <div id="links"> 
      <p><xsl:apply-templates select="description"/></p> 
      description 
      <p><img src="links.jpg"/></p> 
     </div> 
     <div id="news"> 
      <h1>RSS News Feed</h1> 
      items 
     </div> 
     </body> 
    </html> 
    </xsl:template> 
    <xsl:template match="image"> 
    <a href="{../link}"> 
    <xsl:value-of select="."/> 
    </a> 
     <img src="{./url}" alt="{./title}" width="{./width}" 
     height="{./height}" longdesc="{./description}"><xsl:value-of select="."/></img> 
    </xsl:template> 
    <xsl:template match="dc:date"> 
     <xsl:value-of select="/dc:date"/> 
    </xsl:template> 
    <xsl:template match="description"> 
     <xsl:value-of select="/channel/description"/> 
    </xsl:template> 

</xsl:stylesheet> 

,我得到的輸出是究竟什麼是「日期,DES cription,RSS新聞提要和身體部分的項目多數民衆贊成它!請告訴我我做錯了什麼。

+0

如果你告訴我們,你期待什麼輸出這將是有益的。 – 2012-03-13 03:10:47

+0

它應該是一個新聞閱讀器,但沒有一個,XML的內容正在生產只是樣式 – Overcranked 2012-03-13 03:14:36

回答

2

你有幾個錯誤。基本的錯誤是你錯誤地喚起了模板。 例子:

//you need to indicate path to the node 
<xsl:apply-templates select="channel/description"/> 

我已經修正了一些這些的,試試這個:

<?xml version="1.0" encoding="UTF-8" ?> 
<xsl:stylesheet 
    xmlns:xsl= "http://www.w3.org/1999/XSL/Transform" 
     xmlns:rss="http://purl.org/rss/1.0/" version="1.0" 
     xmlns:dc="http://purl.org/dc/elements/1.1/" 
     exclude-result-prefixes="rss dc"> 
    <xsl:output method="html" version="4.0"/> 

    <xsl:template match="rss"> 
    <html> 
     <head> 
     <title> 
      <xsl:value-of select="channel/title"/> 
     </title> 
     <link rel="stylesheet" href="sci.css" type="text/css"/> 
     </head> 
     <body> 
     <div id="logo"> 
      <xsl:apply-templates select="channel/image"/> 
     </div> 
     <div id="datetime"> 
      <xsl:value-of select="channel/dc:date"/>date 
     </div> 

     <div id="links"> 
      <p> 
      <xsl:apply-templates select="channel/description"/> 
      </p> 
      description 
      <p> 
      <img src="links.jpg"/> 
      </p> 
     </div> 
     <div id="news"> 
      <h1>RSS News Feed</h1> 
      items 
     </div> 
     </body> 
    </html> 
    </xsl:template> 
    <xsl:template match="image"> 
    <a href="{../link}"> 
     <xsl:value-of select="."/> 
    </a> 
    <img src="{./url}" alt="{./title}" width="{./width}" 
    height="{./height}" longdesc="{./description}"> 
     <xsl:value-of select="."/> 
    </img> 
    </xsl:template> 
    <xsl:template match="dc:date"> 
    <xsl:value-of select="/dc:date"/> 
    </xsl:template> 
    <xsl:template match="description"> 
    <xsl:value-of select="channel/description"/> lalala TEMPLATE! 
    </xsl:template> 

</xsl:stylesheet> 
+0

這是一個開始它最終識別的一些xml內容,它不是以前。 – Overcranked 2012-03-13 03:23:11

+1

現在您可以繼續前進,並在再次卡住時更新您的問題。 – 2012-03-13 03:30:48

+0

爲什麼將模板xpath從更改爲會產生這樣的差異?和「rss」是指什麼?我認爲將它應用到整個根節點是正確的方法。 – Overcranked 2012-03-13 13:05:48