5

如何在以下代码中插入 youtubeId 参数:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE xsl:stylesheet [ <!ENTITY nbsp "&#x00A0;"> ]>
<xsl:stylesheet 
    version="1.0" 
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
    xmlns:msxml="urn:schemas-microsoft-com:xslt"
                xmlns:YouTube="urn:YouTube"
    xmlns:umbraco.library="urn:umbraco.library"
    exclude-result-prefixes="msxml umbraco.library YouTube">


<xsl:output method="xml" omit-xml-declaration="yes"/>

 <xsl:param name="videoId"/>
<xsl:template match="/">
 <a href="{$videoId}">{$videoId}</a>

<object width="425" height="355">
<param name="movie" value="http://www.youtube.com/v/{$videoId}&amp;hl=en"></param>
<param name="wmode" value="transparent"></param>
<embed src="http://www.youtube.com/v/{$videoId}&amp;hl=en" type="application/x-shockwave-flash" wmode="transparent" width="425" height="355"></embed>
</object>$videoId {$videoId} {$videoId}
 <xsl:value-of select="/macro/videoId" />
</xsl:template>

</xsl:stylesheet>

<xsl:value-of select="/macro/videoId" />实际上输出 videoId 但所有其他事件都没有。

我正在 Umbraco CMS 中创建一个宏。该参数被正确地传递到 XSLT(因为实际上输出了它的值)。如何将此值插入 src 属性?

4

2 回答 2

21
 <a href="{$videoId}">{$videoId}</a>

你必须<xsl:value-of select="$videoId"/>在这里使用:

<a href="{$videoId}"><xsl:value-of select="$videoId"/></a>

每当您在属性值中使用 AVT ( {$videoId}) 时,这必须与任何select属性的例外一起使用。

在最后一种情况下,您可以使用:

<xsl:value-of select="/macro/*[name()=$videoId]" />

当所有这些都反映在您的转换中时,它适用于所有情况

<!DOCTYPE xsl:stylesheet [ <!ENTITY nbsp "&#x00A0;"> ]>
<xsl:stylesheet
    version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:msxml="urn:schemas-microsoft-com:xslt"
                xmlns:YouTube="urn:YouTube"
    xmlns:umbraco.library="urn:umbraco.library"
    exclude-result-prefixes="msxml umbraco.library YouTube">


<xsl:output method="xml" omit-xml-declaration="yes"/>

 <xsl:param name="videoId" select="'XXX'"/>
<xsl:template match="/">
 <a href="{$videoId}"><xsl:value-of select="$videoId"/></a>

<object width="425" height="355">
<param name="movie" value="http://www.youtube.com/v/{$videoId}&amp;hl=en"></param>
<param name="wmode" value="transparent"></param>
<embed src="http://www.youtube.com/v/{$videoId}&amp;hl=en" type="application/x-shockwave-flash" wmode="transparent" width="425" height="355"></embed>
</object><xsl:value-of select="concat($videoId, ' ', $videoId, ' ', $videoId)"/>
 <xsl:value-of select="/macro/*[name()=$videoId]" />
</xsl:template>

</xsl:stylesheet>
于 2010-05-06T13:43:09.487 回答
1

您可能只想获得一个对此也有帮助的软件包。

http://our.umbraco.org很棒,并且一直在添加软件包。

快速搜索会发现一些选项:

http://our.umbraco.org/projects/tag/youtube#projectList

于 2010-05-11T20:15:01.917 回答