2012-03-13 4 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> 

Вывод, который я получаю только то, что находится в «Дата, дез cription, RSS-ленты новостей и предметы в разделе body thats it! скажите, пожалуйста, что я делаю неправильно.

+0

Было бы полезно, если бы вы сказали нам, что вы ожидаете для вывода. –

+0

Предполагается, что это читатель новостей, но ни один из содержимого хml не создается только стилями – Overcranked

ответ

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

+1

Теперь вы можете двигаться вперед и обновлять свой вопрос, когда застряли снова. –

+0

Почему изменение шаблона xpath из в делает такую ​​разницу? и что означает «rss»? Я считаю, что применение этого метода ко всему корневому узлу является правильным способом. – Overcranked

Смежные вопросы