XSLT: insert parameter value inside html attribute

How to insert youtubeId parameter in the following code:

<?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" /> does display videoId, but all other cases do not.

I am creating a macro in CMS Umbraco. The parameter is correctly passed to XSLT (because it actually prints its value). How to insert this value into src attribute?

+4
source share
2 answers
  <a href="{$videoId}">{$videoId}</a> 

Here you should use <xsl:value-of select="$videoId"/> :

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

Whenever you use AVT ( {$videoId} ) inside an attribute value, it should work with the exception of any select attribute.

In the latter case, you can use:

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

When all this is reflected in your transformation, it works in all cases :

 <!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> 
+19
source

You can simply get a package that will also help with this.

http://our.umbraco.org is awesome and packages are being added all the time.

A quick search shows several options:

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

+1
source

Source: https://habr.com/ru/post/1308998/


All Articles