嘿,由于某些原因,我无法将嵌入的YouTube视频用于XSLT。该页面加载了所有数据,但视频由于某种原因没有嵌入。我尝试仅更改源属性,但这导致整个XSLT无法加载,所以我在此处遵循了一个解决方法http://our.umbraco.org/forum/developers/xslt/33745-Fixed-Youtube-embed-through-XSLT现在页面加载正确,除了嵌入。
这是我的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>
这是我的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>
提前感谢您收到的任何帮助:)
答案 0 :(得分:0)
这可以使用模板匹配而不是使用for-each轻松完成,但看起来iframe不会呈现,因为YouTube使用不同的网址进行嵌入/ iframe
http://www.youtube.com/v/2H2XDQqvbpc
而不是
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>