Reputation: 6905
I would like to set an xsl variable based on a condition. The xsl below is not currently working for me. I've been able to make two different matchers (<xsl:template match="rule/condition"
and <xsl:template match="condition/condition"
) which enables me to put the ;display:none
on just condition/condition
matches but that results in the template being duplicated except for the one part of ;display:none
. Guess I'm under the impression that I should be able to dynamically set a variable based on a condition but maybe my impression is wrong?
<xsl:template match="condition">
<xsl:variable name="display">
<xsl:if test='name(..)=condition'>;display=none</xsl:if>
</xsl:variable>
<div style="{$divIndent}{$display}">
<a href="javascript:void(0)" style="{$expandPosition}" onclick="expandContents(this)">
<span class="glyphicon glyphicon-plus"></span>
</a>
<condition type="<xsl:value-of select="@type"/>"><br />
<xsl:apply-templates select="expression" />
<xsl:apply-templates select="condition" />
</condition>
</div>
</xsl:template>
Upvotes: 1
Views: 492
Reputation: 46
Try below code by adding attribute style
<div><xsl:attribute name ="style"><xsl:if test='name(..)=condition'>display=none;</xsl:if></xsl:attribute></div>
Upvotes: 0
Reputation: 1501
<xsl:if test='name(..)=condition'>;display=none</xsl:if>
This asks if the name of the parent is equal to the value of the child whose name is condition. You probably want to know if the name of the parent is the literal value "condition":
<xsl:if test='name(..)="condition"'>;display=none</xsl:if>
However, it might be more idiomatic to write:
<xsl:if test='parent::condition'>;display=none</xsl:if>
Note also that display:none
is valid css, display=none
prbably won't work.
Upvotes: 2