I'm trying to add a condition within a link that looks something like this.
<a class="accordion-toggle" role="button" data-toggle="collapse" data-parent="#accordion" href="#collapse" aria-expanded="true" aria-controls="collapse">
<xsl:value-of select="./Data[@Name='Title']"/>
<div class=""></div>
<xsl:attribute name="class">
<xsl:choose>
<xsl:when test="/Properties/Data[@ID='ISSOCIAL']/Option[@Selected='true']/Value = 1">
pull-right down
</xsl:when>
<xsl:otherwise>
pull-right
</xsl:otherwise>
</xsl:choose>
</xsl:attribute>
</a>
Unfortunately the class inside the div tag looks like this <div class="">
..empty.
However, if I was to just run the following without adding the condition inside the anchor tag it renders fine.
<div class=""></div>
<xsl:attribute name="class">
<xsl:choose>
<xsl:when test="/Properties/Data[@ID='ISSOCIAL']/Option[@Selected='true']/Value = 1">
pull-right down
</xsl:when>
<xsl:otherwise>
pull-right
</xsl:otherwise>
</xsl:choose>
</xsl:attribute>
Output looking like this <div class="pull-right down"></div>
Any ideas on why this is happening? any help would be appreciated!
答案 0 :(得分:1)
如果您要将属性添加到div
,则需要将xsl:attribute
放在div
内。
<div>
<xsl:attribute name="class">
<xsl:choose>
<xsl:when test="/Properties/Data[@ID='ISSOCIAL']/Option[@Selected='true']/Value = 1">
pull-right down
</xsl:when>
<xsl:otherwise>
pull-right
</xsl:otherwise>
</xsl:choose>
</xsl:attribute>
</div>
由于问题被标记为XSLT 2.0,您只需使用
即可<div class="{if (/Properties/Data[@ID='ISSOCIAL']/Option[@Selected='true']/Value = 1) then 'pull-right down' else 'pull-right'}">..</div>