Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/variables/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/xslt/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Variables Umbraco-xslt变量转换为数据属性_Variables_Xslt_Umbraco - Fatal编程技术网

Variables Umbraco-xslt变量转换为数据属性

Variables Umbraco-xslt变量转换为数据属性,variables,xslt,umbraco,Variables,Xslt,Umbraco,我在xslt中有一个值,需要将其放入p标记的数据时间属性中 <xsl:value-of select="current()/eventTime" /> <p class="time" data-time="1">Duration: <xsl:value-of select="current()/eventTime" /> hour(s)</p> 持续时间:小时 这会产生一个错误 <p class="time" data-time="

我在xslt中有一个值,需要将其放入p标记的数据时间属性中

 <xsl:value-of select="current()/eventTime" />
 <p class="time" data-time="1">Duration: <xsl:value-of select="current()/eventTime" /> hour(s)</p>

持续时间:小时

这会产生一个错误

<p class="time" data-time="<xsl:value-of select="current()/eventTime" />">Duration: <xsl:value-of select="current()/eventTime" /> hour(s)</p>
持续时间:小时

你知道我是如何做到这一点的吗?

“属性值模板”是你的朋友

<p class="time" data-time="{current()/eventTime}">
   Duration: <xsl:value-of select="current()/eventTime" /> hour(s)
</p> 

持续时间:小时(s)

大括号表示这是一个属性值模板,因此包含一个要计算的表达式

请注意,另一种方法是使用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> 

持续时间:小时(s)

但这并不那么优雅。只有在需要动态属性名的情况下,才需要这样做。

像这样的吗

<xsl:variable name="eventtime" select="current()/eventTime"/>

<xsl:element name="p">
  <xsl:attribute name="class">time</xsl:attribute>
  <xsl:attribute name="data-time">
     <xsl:value-of select="$eventtime" />
  </xsl:attribute>
  Duration: 
  <xsl:value-of select="$eventtime" />
</xsl:element>

时间
持续时间:
代替
也可以在“
{}
”括号中使用缩写形式。在您的情况下,它将是这样的:


持续时间:小时