如何选择元素im:name

时间:2015-12-22 01:14:41

标签: xml xslt

您好我试图选择一个元素即时通讯:某事。我想在我的xsl文件中选择它,以便我可以在浏览我的xml文件时显示它。我寻找一整天的蜜蜂让这个工作。所以请帮助我。

这里是文件的开头

<?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。正如您在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>

一切正常,<xsl:value-of select='atom:im:name'/>

当我浏览此内容时,我收到错误Expected token 'eof' found ':'. atom:im-->:<--name

1 个答案:

答案 0 :(得分:1)

您不能使用两个名称空间(atom:im:name结合两个名称空间前缀)。您必须在XSLT中声明im命名空间:

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

声明im前缀后,您可以在XPath表达式中选择元素im:name。但是,只使用im:name,这些不是atom命名空间中的元素。