Domanda

Hey I cant get the embedding of a youtube video to work in XSLT for some reason. The page loads fine with all the data but the video doesn't embed for some reason. I tried changing just the source attribute but that caused the whole of the XSLT not to load, so i followed a workaround here http://our.umbraco.org/forum/developers/xslt/33745-Fixed-Youtube-embed-through-XSLT now the page loads correctly apart from the embed.

Here is my XML:

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

<dalehoward>
<bio>
<profilepic>profilepic.jpg</profilepic>
<dob>16/10/1987</dob>
<pob>Liverpool</pob>
<about>
English Deep House producer Dale Howard first burst onto the scene in 2009 with his debut EP on Neurotraxx Deluxe Gotta Be Deep, which topped the Beatport Deep House chart reaching the Number 1 spot. Since then he has been making waves with an array of releases on world renowned labels like Fear Of Flying, Loco Records and many others. Aswell as having countless top 20's and 50's Dale has also reached Number 2 and Number 3 on the Beatport Deep House Chart with his tracks 'Dropout' and 4 Hour Bang, which also stayed in the Top 10 for 9 weeks. In 2010 Dale launched his own imprint Static Audio, which is a hotbed for established and up and coming Deep and Tech House producers alike and features some of the biggest Deep House artists in the world. With his productions having support from artists like Richie Hawtin, Nic Fancuilli, Mark Knight, Florian Meindl, Funkagenda, Karol XVII and MB Valence, Ekkohaus, Robert Owens, Filthy Rich, Ronan Portela, Soul Miniority and a load more, Dale continues to make Top notch Deep House and has forthcoming releases on even more of the worlds finest House labels.
</about>
</bio>
<ep id="1">
    <name>Letters EP</name>
    <year>2012</year>
    <label>Static Audio</label>
    <image>letters.jpg</image>

        <track number="1" beatportrank="0">
            <tname>Letters</tname>
            <length>6.35</length>
            <ytubelink>https://www.youtube.com/watch?v=2H2XDQqvbpc</ytubelink>
        </track>
        <track number="2" beatportrank="0">
            <tname>Later</tname>
            <length>7.56</length>
            <ytubelink>https://www.youtube.com/watch?v=w61RrgBPahk</ytubelink>
        </track>
            <track number="3" beatportrank="0">
            <tname>'89 Flava</tname>
            <length>7:38</length>
            <ytubelink>https://www.youtube.com/watch?v=Mgarl-FlVhQ</ytubelink>
        </track>
        <track number="4" beatportrank="0">
            <tname>Safe Presentation</tname>
            <length>7.55</length>
            <ytubelink>https://www.youtube.com/watch?v=d_U38G9AwHk</ytubelink>
        </track>
</ep>



<ep id="2">
    <name>Inner City EP</name>
    <year>2012</year>
    <label>Lost My Dog</label>
    <image>innercity.jpg</image>

    <track number="1" beatportrank="0">
            <tname>C'Mon</tname>
            <length>7.15</length>
            <ytubelink>https://www.youtube.com/watch?v=Y9ExPTumGg4</ytubelink>
        </track>
        <track number="2" beatportrank="0">
            <tname>Koppabird</tname>
            <length>6.27</length>
            <ytubelink>https://www.youtube.com/watch?v=RrSgPq9gw9E</ytubelink>
        </track>
        <track number="3" beatportrank="0">
            <tname>Inner City</tname>
            <length>8:50</length>
            <ytubelink>https://www.youtube.com/watch?v=zuABxrp5A2U</ytubelink>
        </track>
        <track number="4" beatportrank="0">
            <tname>You Can</tname>
            <length>8:16</length>
            <ytubelink>https://www.youtube.com/watch?v=oxFynevJf6Y</ytubelink>
        </track>
</ep>
</dalehoward>

Here is my XSLT:

<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:variable name="imagefolder" select="'xml/images/'" />
<xsl:template match="/">


<html>
<body>
<table border="1px"  bordercolor="#FFFFFF" width="100%">
  <tr bgcolor="#cccccc">
    <th style="text-align:left">Title</th>
    <th style="text-align:left">Year</th>
    <th style="text-align:left">Label</th>
    <th style="text-align:left">Tracks</th>
    <th style="text-align:left">Artwork</th>
  </tr>
  <xsl:for-each select="dalehoward/ep">
  <xsl:sort select="year" order="ascending" data-type="number"/>
  <xsl:if test="@id = 1">
  <tr>
    <td><xsl:value-of select="name"/></td>
    <td><xsl:value-of select="year"/></td>
    <td><xsl:value-of select="label"/></td>
    <td><xsl:for-each select="track">
        <xsl:if test="../@id = 1">
        <xsl:value-of select="@number"/>.
        <xsl:value-of select="tname"/><br />
        <xsl:value-of select="length"/> <br /><br />

        <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"><xsl:value-of select="ytubelink"/></xsl:attribute>
    <xsl:attribute name="frameborder">0</xsl:attribute>
    <xsl:comment/>
</xsl:element> <br /><br />

        </xsl:if>
        </xsl:for-each></td>
    <td><img width="150px" height="150px"><xsl:attribute name="src">
             <xsl:copy-of select="$imagefolder"/>
             <xsl:value-of select="image"/>
             </xsl:attribute></img></td>
  </tr>
  </xsl:if>
  </xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>

Thanks in advance for any help received :)

È stato utile?

Soluzione

This can be easily done using template matches instead of using for-each but looks like the iframe is not rendering because YouTube uses a different URL for embedding/iframes

http://www.youtube.com/v/2H2XDQqvbpc

instead of

https://www.youtube.com/watch?v=2H2XDQqvbpc

<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:variable name="imagefolder" select="'xml/images/'" />
<xsl:template match="/">
<html>
<body>
    <table border="1px"  bordercolor="#FFFFFF" width="100%">
        <tr bgcolor="#cccccc">
            <th style="text-align:left">Title</th>
            <th style="text-align:left">Year</th>
            <th style="text-align:left">Label</th>
            <th style="text-align:left">Tracks</th>
            <th style="text-align:left">Artwork</th>
        </tr>
        <xsl:for-each select="dalehoward/ep">
            <xsl:sort select="year" order="ascending" data-type="number"/>
            <xsl:if test="@id = 1">
                <tr>
                    <td><xsl:value-of select="name"/></td>
                    <td><xsl:value-of select="year"/></td>
                    <td><xsl:value-of select="label"/></td>
                    <td><xsl:for-each select="track">
                        <xsl:if test="../@id = 1">
                            <xsl:value-of select="@number"/>.
                            <xsl:value-of select="tname"/><br />
                            <xsl:value-of select="length"/> <br /><br />

                            <xsl:variable name="vid">
                                <xsl:analyze-string select="ytubelink" regex="(((https://)?)((http://)?)(www\.)?((youtube\.com/)|(youtu\.be)|(youtube))(.+=)(.+))">
                                    <xsl:matching-substring>http://www.youtube.com/v/<xsl:value-of select="regex-group(12)"/></xsl:matching-substring>
                                    <xsl:non-matching-substring>
                                        <xsl:copy-of select="."/>
                                    </xsl:non-matching-substring>
                                </xsl:analyze-string>
                            </xsl:variable>

                            <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"><xsl:value-of select="$vid"/></xsl:attribute>
                                <xsl:attribute name="frameborder">0</xsl:attribute>
                                <xsl:comment/>
                            </xsl:element> <br /><br />

                        </xsl:if>
                    </xsl:for-each></td>
                    <td><img width="150px" height="150px"><xsl:attribute name="src">
                        <xsl:copy-of select="$imagefolder"/>
                        <xsl:value-of select="image"/>
                    </xsl:attribute></img></td>
                </tr>
            </xsl:if>
        </xsl:for-each>
    </table>
</body>
</html>
</xsl:template>


</xsl:stylesheet>
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top