Dealing with an XSLT Namespace Mismatch

Qmgyzcfxwr

New Member
So, hopefully this will be my final request for help on this project, as you guys have already helped so much already.Basically, I'm writing some code that takes a YouTube playlist and converts it to an RSS feed. I've gotten it to work the way I want to, except for one minor detail: I'm not sure why, but I need to remove one of the namespaces from the YouTube XML before it will compile.The namespace declaration from YouTube looks like this:\[code\]<feed xmlns:media='http://search.yahoo.com/mrss/' xmlns:openSearch='http://a9.com/-/spec/opensearch/1.1/' xmlns:gd='http://schemas.google.com/g/2005' xmlns:gml='http://www.opengis.net/gml' xmlns:yt='http://gdata.youtube.com/schemas/2007' xmlns:georss='http://www.georss.org/georss' gd:etag='W/"A04NRn47eCp7I2A9WhJTF0g."'>\[/code\]Normally, I'd use the exact same ones, except for whatever reason if I include the \[code\]xmlns='http://www.w3.org/2005/Atom'\[/code\] segment, the whole thing returns null.Up until now, my technique has been to just chop that line out of the YouTube XML, however this strikes me as a tad inelegant. If someone who knows more about this than I do could point out what's wrong with my current code, I'd greatly appreciate it.AdamEDIT: For reference, here's my XSLT:\[code\]<?xml version="1.0" encoding="UTF-8"?><xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns='http://www.w3.org/2005/Atom' xmlns:media='http://search.yahoo.com/mrss/' xmlns:openSearch='http://a9.com/-/spec/opensearch/1.1/' xmlns:gd='http://schemas.google.com/g/2005' xmlns:yt='http://gdata.youtube.com/schemas/2007' gd:etag='W/"Ak8EQX47eCp7I2A9WhdSEkQ."'><xsl:template match="/"><xsl:for-each select="entry"><xsl:if test="yt:position < 3"> <item> <title><xsl:value-of select="title" /></title> <xsl:variable name="videoid" select="substring-before(substring-after(media:group/media:content/@url, 'v/'), '?')" /> <!--Extracting the YouTube video ID--> <description> <embed src="http://www.youtube.com/v/{$videoid}" type="application/x-shockwave-flash" allowscriptaccess="never" allowfullscreen="true" width="500" height="300"></embed> <!--Embed code for the video--> <br /> <br /> <xsl:call-template name="ParseLink"> <!--Parses the video description such that URLs become links--> <xsl:with-param name="text" select="media:group/media:description" /> </xsl:call-template> <img src="http://i.ytimg.com/vi/{$videoid}/hqdefault.jpg" style="display:none"/> <!--Includes hidden thumbnail--> </description> <link>http://www.youtube.com/watch?v=<xsl:value-of select="$videoid" /></link> <!--Link to video on YouTube--> <guid isPermaLink="false">http://www.youtube.com/watch?v=<xsl:value-of select="$videoid" /></guid> </item></xsl:if></xsl:for-each></xsl:template><xsl:template name="ParseLink"> <!--YouTube automatically turns URLs into links, this performs the same function for RSS--> <xsl:param name="text"/> <xsl:choose> <xsl:when test="contains($text,'http')"> <a href="http://stackoverflow.com/questions/11234537/http{substring-before(substring-after($text,'http'), '
')}">Watch the complete video on our website</a> <br/> <xsl:call-template name="ParseText"> <!--Once the link is found, parses the rest of the text--> <xsl:with-param name="text"> <xsl:value-of select="substring-after($text,'
')"/> </xsl:with-param> </xsl:call-template> </xsl:when> <xsl:otherwise> <xsl:value-of select="$text"/> </xsl:otherwise> </xsl:choose></xsl:template><xsl:template name="ParseText"> <!--Replaces line breaks in the description to <br> tags--> <xsl:param name="text"/> <xsl:choose> <xsl:when test="contains($text,'
')"> <xsl:value-of select="substring-before($text,'
')"/> <br /> <xsl:call-template name="ParseText"> <xsl:with-param name="text"> <xsl:value-of select="substring-after($text,'
')"/> </xsl:with-param> </xsl:call-template> </xsl:when> <xsl:otherwise> <xsl:value-of select="$text"/> </xsl:otherwise> </xsl:choose></xsl:template>\[/code\]
 
Back
Top