ですから、うまくいけば、これがこのプロジェクトに関する私の最後のリクエストになると思います。
基本的には、YouTube プレイリストを取得して RSS フィードに変換するコードを書いています。1 つの小さな詳細を除いて、希望どおりに動作するようになりました。理由はわかりませんが、コンパイルする前に、YouTube XML から名前空間の 1 つを削除する必要があります。
YouTube の名前空間宣言は次のようになります。
<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."'>
通常、まったく同じものを使用しますが、何らかの理由でxmlns='http://www.w3.org/2005/Atom'
セグメントを含めると、全体が null を返します。
これまで、私のテクニックは YouTube XML からその行を切り取っていましたが、これは少し洗練されていないように思えます。これについて私よりも詳しい人が、現在のコードの何が問題なのかを指摘できれば、非常にありがたいです。
アダム
編集:参考までに、ここに私のXSLTがあります:
<?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{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>