代码之家  ›  专栏  ›  技术社区  ›  usr

XSLT:在html属性中插入参数值

  •  4
  • usr  · 技术社区  · 16 年前

    如何在以下代码中插入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属性?

    2 回复  |  直到 11 年前
        1
  •  21
  •   Dimitre Novatchev    16 年前
     <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>
    
        2
  •  1
  •   BeaverProj    16 年前

    你可能想得到一个包,也有助于这一点。

    http://our.umbraco.org

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

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