2015-12-22 81 views
0

嗨,我試圖選擇一個元素im:東西。我想在我的xsl文件中選擇它,以便在瀏覽我的xml文件時顯示它。我已經尋找了一整天讓這項工作。所以請幫助我。如何選擇元素im:名稱

這裏的文件

<?xml version="1.0" encoding="UTF-8"?> 
<?xml-stylesheet type="text/xsl" href="C:\*\ItunesFilms.xsl"?> 
<itunesfilms> 
<feed xmlns:im="http://itunes.apple.com/rss" xmlns="http://www.w3.org/2005/Atom" xml:lang="en"> 
    <id> 
https://itunes.apple.com/be/rss/topmovies/limit=10/genre=4401/xml 
</id> 
    <title>iTunes Store: Top Films in Action &amp; Adventure</title> 
    <updated>2015-12-19T07:24:47-07:00</updated> 
    <link rel="alternate" type="text/html" href="html_link"/> 
    <link rel="self" href="html_link"/> 
    <icon>html_link.ico</icon> 
    <author> 
     <name>iTunes Store</name> 
     <uri>html_link</uri> 
    </author> 
    <rights>Copyright 2008 Apple Inc.</rights> 
    <entry> 
     <updated>2015-12-19T07:24:47-07:00</updated> 
     <id im:id="1017058143">html_link</id> 
     <title> 
Mission: Impossible - Rogue Nation - Christopher McQuarrie 
</title> 
     <summary> 
Loaded with heart-pounding action and jaw-dropping stunts, prepare for the best Mission ever. With his elite organization shut down by the CIA, agent Ethan Hunt (Tom Cruise) and his team (Jeremy Renner, Simon Pegg, Ving Rhames) race against time to stop the rise of a new global threat, The Syndicate, a dangerous network of rogue operatives turned traitors. To stop them, Ethan must join forces with an elusive, disavowed agent (Rebecca Ferguson) who may or may not be on his side as he faces his most impossible mission yet. 
</summary> 
     <im:name>Mission: Impossible - Rogue Nation</im:name> 
     <link rel="alternate" type="text/html" href="html_link"/> 
     <im:contentType term="Movie" label="Films"/> 
     <category im:id="4401" term="Action &amp;amp; Adventure" scheme="html_link" label="Action &amp; Adventure"/> 
     <link title="Preview" rel="enclosure" type="video/x-m4v" href="html_link" im:assetType="preview"> 
      <im:duration>145657.0</im:duration> 
     </link> 
     <im:artist>Christopher McQuarrie</im:artist> 
     <im:price amount="16.99000" currency="EUR">16,99 €</im:price> 
     <im:rentalPrice amount="3.99000" currency="EUR">3,99 €</im:rentalPrice> 
     <im:image height="60">html_link.jpg</im:image> 
     <im:image height="60">html_link.jpg</im:image> 
     <im:image height="170">html_link.jpg</im:image> 
     <rights>© 2015 PARAMOUNT PICTURES. ALL RIGHTS RESERVED.</rights> 
     <im:releaseDate label="31 July 2015">2015-07-31T00:00:00-07:00</im:releaseDate> 
     <content type="html"> 
      <table border="0" width="100%"> 
       <tr> 
        <td> 
         <table border="0" width="100%" cellspacing="0" cellpadding="0"> 
          <tr valign="top" align="left"> 
           <td align="center" width="166" valign="top"> 
            <a href="html_link"> 
             <img border="0" alt="Christopher McQuarrie - Mission: Impossible - Rogue Nation artwork" src="html_link.jpg"/> 
            </a> 
           </td> 
           <td width="10"> 
            <img alt="" width="10" height="1" src="html_link"/> 
           </td> 
           <td width="95%"> 
            <b> 
             <a href="html_link">Mission: Impossible - Rogue Nation</a> 
            </b> 
            <br/> Christopher McQuarrie <font size="2" face="Helvetica,Arial,Geneva,Swiss,SunSans-Regular"> 
             <br/> 
             <b>Genre:</b> 
             <a href="html_link">Action &amp;amp; Adventure</a> 
             <br/> 
             <b>Price:</b> 16,99 € <br/> 
             <b>Rental Price:</b> 3,99 € <br/> 
             <b>Release Date:</b> 31 July 2015 </font> 
           </td> 
          </tr> 
         </table> 
        </td> 
       </tr> 
       <tr> 
        <td> 
         <font size="2" face="Helvetica,Arial,Geneva,Swiss,SunSans-Regular"> 
          <br/>Loaded with heart-pounding action and jaw-dropping stunts, prepare for the best Mission ever. With his elite organization shut down by the CIA, agent Ethan Hunt (Tom Cruise) and his team (Jeremy Renner, Simon Pegg, Ving Rhames) race against time to stop the rise of a new global threat, The Syndicate, a dangerous network of rogue operatives turned traitors. To stop them, Ethan must join forces with an elusive, disavowed agent (Rebecca Ferguson) who may or may not be on his side as he faces his most impossible mission yet.</font> 
         <br/> 
         <font size="2" face="Helvetica,Arial,Geneva,Swiss,SunSans-Regular"> &amp#169; © 2015 PARAMOUNT PICTURES. ALL RIGHTS RESERVED.</font> 
        </td> 
       </tr> 
      </table> 
     </content> 
    </entry> 
    <entry> 
     <updated>2015-12-19T07:24:47-07:00</updated> 
     <id im:id="991367195">html_link</id> 
     <title>Minions - Pierre Coffin &amp; Kyle Balda</title> 
     <summary> 
Since the dawn of time, Minions have served (and accidentally eliminated) history's most despicable villains. After their latest explosive mistake leaves them without an evil leader, the Minions fall into a deep depression. With the tribe on the brink of collapse, three unlikely heroes—Kevin, Stuart, and Bob—embark on a journey to find a new big boss. When their quest leads them to their next potential master, Scarlet Overkill (Academy Award® winner Sandra Bullock), our three heroes must face their biggest challenge yet: saving all of Minionkind… from annihilation! 
</summary> 
     <im:name>Minions</im:name> 
     <link rel="alternate" type="text/html" href="html_link"/> 
     <im:contentType term="Movie" label="Films"/> 
     <category im:id="4410" term="Kids &amp;amp; Family" scheme="html_link" label="Kids &amp;amp; Family"/> 
     <link title="Preview" rel="enclosure" type="video/x-m4v" href="html_link.m4v" im:assetType="preview"> 
      <im:duration>164372.0</im:duration> 
     </link> 
     <im:artist>Pierre Coffin &amp; Kyle Balda</im:artist> 
     <im:price amount="13.99000" currency="EUR">13,99 €</im:price> 
     <im:rentalPrice amount="3.99000" currency="EUR">3,99 €</im:rentalPrice> 
     <im:image height="60">html_link.jpg</im:image> 
     <im:image height="60">html_link.jpg</im:image> 
     <im:image height="170">html_link.jpg</im:image> 
     <rights>© 2015 Universal Studios. All Rights Reserved.</rights> 
     <im:releaseDate label="10 July 2015">2015-07-10T00:00:00-07:00</im:releaseDate> 
     <content type="html"> 
      <table border="0" width="100%"> 
       <tr> 
        <td> 
         <table border="0" width="100%" cellspacing="0" cellpadding="0"> 
          <tr valign="top" align="left"> 
           <td align="center" width="166" valign="top"> 
            <a href="html_link"> 
             <img border="0" alt="Pierre Coffin &amp;amp; Kyle Balda - Minions artwork" src="html_link.jpg"/> 
            </a> 
           </td> 
           <td width="10"> 
            <img alt="" width="10" height="1" src="html_link.gif"/> 
           </td> 
           <td width="95%"> 
            <b> 
             <a href="html_link">Minions</a> 
            </b> 
            <br/> Pierre Coffin &amp; Kyle Balda <font size="2" face="Helvetica,Arial,Geneva,Swiss,SunSans-Regular"> 
             <br/> 
             <b>Genre:</b> 
             <a href="html_link">Kids &amp; Family</a> 
             <br/> 
             <b>Price:</b> 13,99 € <br/> 
             <b>Rental Price:</b> 3,99 € <br/> 
             <b>Release Date:</b> 10 July 2015 </font> 
           </td> 
          </tr> 
         </table> 
        </td> 
       </tr> 
       <tr> 
        <td> 
         <font size="2" face="Helvetica,Arial,Geneva,Swiss,SunSans-Regular"> 
          <br/>Since the dawn of time, Minions have served (and accidentally eliminated) history&amp;#39;s most despicable villains. After their latest explosive mistake leaves them without an evil leader, the Minions fall into a deep depression. With the tribe on the brink of collapse, three unlikely heroes—Kevin, Stuart, and Bob—embark on a journey to find a new big boss. When their quest leads them to their next potential master, Scarlet Overkill (Academy Award® winner Sandra Bullock), our three heroes must face their biggest challenge yet: saving all of Minionkind… from annihilation!</font> 
         <br/> 
         <font size="2" face="Helvetica,Arial,Geneva,Swiss,SunSans-Regular"> &amp;amp;#169; © 2015 Universal Studios. All Rights Reserved.</font> 
        </td> 
       </tr> 
      </table> 
     </content> 
    </entry> 

的開始,因爲你可以看到它是RSS格式的iTunes。正如你可以看到int xml文件中有很多im:*元素。我想知道如何選擇它們。

在這裏你可以看到我的XSL文件:

<?xml version="1.0" encoding="UTF-8"?> 
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:atom="http://www.w3.org/2005/Atom"> 
<xsl:template match="itunesfilms" > 
<html xmlns="http://www.w3.org/1999/xhtml"> 
<body> 
    <xsl:apply-templates select="atom:feed"/> 
</body> 
</html> 
</xsl:template> 
<xsl:template match="atom:feed"> 
<head> 
<title>ItunesFIlms</title> 
<style type="text/css"> 
/* some css */ 
</style> 
</head> 
<body> 
<div style="kop"> 
    <h1><xsl:value-of select="atom:title"/><small><xsl:value-of select="atom:rights"/></small></h1> 
    <p>source: <xsl:value-of select="atom:id"/></p> 
</div> 
<div> 
<table class="tg"> 
<xsl:for-each select="atom:entry"> 
    <tr> 
    <th class="tg-yw4l" colspan="5"><h4><xsl:value-of select="atom:title"/></h4><small><xsl:value-of select="atom:rights"/></small></th> 
    </tr> 
    <tr> 
    <td class="tg-yw4l" colspan="4"><xsl:value-of select="atom:summary" disable-output-escaping="yes"/></td> 
    <td class="tg-yw4l"> 
     <img style="foto"> 
      <xsl:attribute name="src"><xsl:value-of select="atom:link/@href [last()]"/></xsl:attribute> 
     </img> 
     <a> 
      <xsl:attribute name="href"><xsl:value-of select="atom:link/@href"/></xsl:attribute> 
      <xsl:value-of select='atom:im:name'/> 
      </xsl:element> 
     </a> 
    </td> 
    </tr> 
    </xsl:for-each> 
</table> 
</div> 
<xsl:for-each select="atom:entry"> 
<div class="con3"> 
<xsl:copy-of select="atom:content/node()" /> 
</div> 
</xsl:for-each> 
</body> 
</xsl:template></xsl:stylesheet> 

一切工作expept <xsl:value-of select='atom:im:name'/>

當我瀏覽這個我得到Expected token 'eof' found ':'. atom:im-->:<--name

回答

1

不能使用兩個命名空間的錯誤(atom:im:name結合了兩種命名空間前綴)。你必須聲明im命名空間中的XSLT:

<xsl:stylesheet ... xmlns:im="http://itunes.apple.com/rss" 

聲明im前綴後,您可以在XPath表達式中選擇元素im:name。只使用im:name,但這些不是來自​​名稱空間的元素。

+0

這使得sence。它的作品謝謝。 – Coo101

相關問題