xml XSLT:在 html 属性中插入参数值
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2781266/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
XSLT: insert parameter value inside of an html attribute
提问by usr
How can I insert the youtubeId parameter in the following code :
如何在以下代码中插入 youtubeId 参数:
<?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.
<xsl:value-of select="/macro/videoId" />实际上输出 videoId 但所有其他事件都没有。
I am creating a macro in Umbraco CMS. The parameter is correctly passed into the XSLT (because actually outputs its value). How can I insert this value into the src-attribute?
我正在 Umbraco CMS 中创建一个宏。参数被正确传递到 XSLT 中(因为实际上输出了它的值)。如何将此值插入到 src-attribute 中?
回答by Dimitre Novatchev
<a href="{$videoId}">{$videoId}</a>
<a href="{$videoId}">{$videoId}</a>
You must use <xsl:value-of select="$videoId"/>here:
你必须<xsl:value-of select="$videoId"/>在这里使用:
<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 selectattribute.
每当您{$videoId}在属性值中使用 AVT ( ) 时,这必须适用于任何select属性除外。
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>
回答by BeaverProj
You may want to just get a package that helps with this as well.
您可能只想获得一个有助于解决此问题的软件包。
http://our.umbraco.orgis awesome and packages are being added all the time.
http://our.umbraco.org很棒,并且一直在添加软件包。
A quick search reveals a few options:
快速搜索会显示几个选项:

