XSLT: insert parameter value inside of an html attribute
How can I insert the youtubeId parameter in the following code :
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE xsl:stylesheet [ <!ENTITY nbsp " "> ]>
<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}&hl=en"></param>
<param name="wmode" value="transparent"></param>
<embed src="http://www.youtube.com/v/{$videoId}&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" />
actually outputs the videoId but all other occurences do not.
I am creating a macro in Umbraco CMS. The p开发者_开发知识库arameter is correctly passed into the XSLT (because actually outputs its value). How can I insert this value into the src-attribute?
<a href="{$videoId}">{$videoId}</a>
You must use <xsl:value-of select="$videoId"/>
here:
<a href="{$videoId}"><xsl:value-of select="$videoId"/></a>
Whenever You are using an AVT ({$videoId}
) inside an attribute value this must work with the exception of any select
attribute.
In the last case you can use:
<xsl:value-of select="/macro/*[name()=$videoId]" />
When all of these are reflected in your transformation, it works in all cases:
<!DOCTYPE xsl:stylesheet [ <!ENTITY nbsp " "> ]>
<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}&hl=en"></param>
<param name="wmode" value="transparent"></param>
<embed src="http://www.youtube.com/v/{$videoId}&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>
You may want to just get a package that helps with this as well.
http://our.umbraco.org is awesome and packages are being added all the time.
A quick search reveals a few options:
http://our.umbraco.org/projects/tag/youtube#projectList
精彩评论