LeB*_*eau 6 xslt variables umbraco
我在xslt中有一个值,我需要把它放到p标签的data-time属性中
<xsl:value-of select="current()/eventTime" />
<p class="time" data-time="1">Duration: <xsl:value-of select="current()/eventTime" /> hour(s)</p>
Run Code Online (Sandbox Code Playgroud)
这会产生错误
<p class="time" data-time="<xsl:value-of select="current()/eventTime" />">Duration: <xsl:value-of select="current()/eventTime" /> hour(s)</p>
Run Code Online (Sandbox Code Playgroud)
知道我是怎么做到的吗?
Tim*_*m C 19
"属性值模板"是您的朋友
<p class="time" data-time="{current()/eventTime}">
Duration: <xsl:value-of select="current()/eventTime" /> hour(s)
</p>
Run Code Online (Sandbox Code Playgroud)
花括号表示这是一个属性值模板,因此包含要计算的表达式.
请注意,另一种方法是使用xsl:attribute元素
<p class="time">
<xsl:attribute name="data-time">
<xsl:value-of select="current()/eventTime" />
</xsl:attribute>
Duration: <xsl:value-of select="current()/eventTime" /> hour(s)
</p>
Run Code Online (Sandbox Code Playgroud)
但这并不是那么优雅.如果需要动态属性名称,您只需要这样做.
| 归档时间: |
|
| 查看次数: |
11530 次 |
| 最近记录: |