2012-09-21 12 views
5

mam wartości w XSLT i muszę umieścić go w atrybucie danych w czasie znacznika pUmbraco - XSLT zmienna w danych atrybutów

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

Stwarza to błąd

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

jakiś pomysł, jak to osiągnąć?

Odpowiedz

15

wartość atrybutu „Szablony” to twój przyjaciel tutaj

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

Nawiasy klamrowe wskazują, że jest to atrybut Wartość szablonu, a więc zawiera wyrażenie zostać ocenione.

Należy zauważyć, że alternatywny sposób byłoby użyć xsl: attribute elementem

<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> 

To nie jest tak elegancki choć. Tak naprawdę musielibyśmy robić to w ten sposób, gdybyśmy chcieli uzyskać nazwę atrybutu dynamicznego.

+0

piękne eleganckie rozwiązanie dziękuję. – LeBlaireau

0

Coś takiego?

<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> 
Powiązane problemy