tags:

views:

221

answers:

1

I can't get this working for the life of me. Here is a snippet of the xml I get from an RSS feed from itunes affiliate. I want top print the values within tags but I cannot for some reason:

<?xml version="1.0" encoding="utf-8"?>

    <feed xmlns:im="http://itunes.apple.com/rss" xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
            <id>http://ax.itunes.apple.com/WebObjects/MZStoreServices.woa/ws/RSS/toppaidapplications/sf=143441/limit=100/genre=6014/xml&lt;/id&gt;&lt;title&gt;iTunes Store: Top Paid Applications</title><updated>2010-03-24T15:36:42-07:00</updated><link rel="alternate" type="text/html" href="http://itunes.apple.com/WebObjects/MZStore.woa/wa/viewTop?id=25180&amp;amp;popId=30"/&gt;&lt;link rel="self" href="http://ax.itunes.apple.com/WebObjects/MZStoreServices.woa/ws/RSS/toppaidapplications/sf=143441/limit=100/genre=6014/xml"/&gt;&lt;icon&gt;http://phobos.apple.com/favicon.ico&lt;/icon&gt;&lt;author&gt;&lt;name&gt;iTunes Store</name><uri>http://www.apple.com/itunes/&lt;/uri&gt;&lt;/author&gt;&lt;rights&gt;Copyright 2008 Apple Inc.</rights>

                    <entry>
                            <updated>date</updated>

                                    <id>someID</id>

                                    <title>a</title>
                                    <im:name>b</im:name>
                    </entry>
                    <entry>
                            <updated>date2/updated>

                                    <id>someID2</id>

                                    <title>a2</title>
                                    <im:name>b2</im:name>
                    </entry>
    </feed>

If I try <xsl:apply-templates match="entry"/> it spits out the entire contents of file. If I use <xsl:call-template name="entry"> it will show only one entry and I have to use <xsl:value-of select="//*[local-name(.)='name']"/> to get name but that's a hack. I've used xslt before for xml without namespaces and xml that has proper parent child relationships but not like this RSS feed. Notice entry is not wrapped in entries or anything.

Any help is appreciated. I want to use xslt because I want to alter the itunes link to go through my affiliate account - so something automated wouldn't work for me.

+1  A: 

You are matching elements that are in no namespace, but the actual elements in the XML document do belong to a (deafult) namspace: xmlns="http://www.w3.org/2005/Atom".

Therefore, you need to declare the namespace in your stylesheet, let's say xmlns:atom="http://www.w3.org/2005/Atom". and then match not just on {elementName} but on {atom:elementName}, where {elementName} in your case is: "entry".

Dimitre Novatchev
I tried what you said but my brain is blocking the concept. Here is what I attempted but no results. feed is top element right? I tried atom:entry but it does not make it to my entry template. Thanks.<xsl:template match="atom:feed"><xsl:apply-templates select="entry"/></xsl:template><xsl:template match="entry">...
jd
Here is my xslt header.<?xml version="1.0"?><xsl:stylesheet version="1.0" xmlns:im="http://itunes.apple.com/rss" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
jd
@jd: Then, replace your XSLT instruction: `<xsl:apply-templates match="entry"/>` with `<xsl:apply-templates match="atom:entry"/>` Also, replace in a similar way all other names of elements, from `elementName` to `atom:elementName`
Dimitre Novatchev
Thanks so much Dimitre! I swear I tried that. I tried many combinations. It works now though. I've been using this site for years and can usually find what I need by looking at other questions but this one I just couldn't grasp so I signed up. I'll be helping others on here now.
jd
@jd, You are most welcome! Glad to have been useful.
Dimitre Novatchev