Fixed: Youtube embed through XSLT

Just spent the last hour to figure out why my "embed-youtube" xslt was breaking my page layout (hiding all HTML that came after the video embed code).

Then finally it struck me that it was because there was no data between the iframe start and end tag and xslt does not seem to like that :/

<iframe width="100" height="100"> 'empty space' </iframe>

So with a little work around i got i working:

<xsl:param name="currentPage"/>
<xsl:variable name="video" select="$currentPage/frontpageMedia"/>

<xsl:template match=“/”>

<!-- start writing XSLT –>
<xsl:if test=“$video != ‘’ “>
<xsl:element name=“iframe”>
<xsl:attribute name=“class”>cf</xsl:attribute>
<xsl:attribute name=“width”>440</xsl:attribute>
<xsl:attribute name=“height”>260</xsl:attribute>
<xsl:attribute name=“src”>YouTube select=”$video”/></xsl:attribute>
<xsl:attribute name=“frameborder”>0</xsl:attribute>
<xsl:comment/><!-- avoid empty tag value that breaks the html–>
</xsl:element>
</xsl:if>

</xsl:template>

$currentPage/frontpageMedia is a Singleline text field where the key for the youtube video is pasted into.

I.E: PbK9eybE35E

Hope it can help someone in a similar situation.

Have a nice day :-)


This is a companion discussion topic for the original entry at https://our.umbraco.com/forum/33745-fixed-youtube-embed-through-xslt