Following code in xslt (I've cut out the irrelevant parts, get-textblock is a lot longer and has a lot of parameters which are all passed correctly):
<xsl:template name="get-textblock">
<xsl:param name="style"/>
<xsl:element name="Border">
<xsl:if test="$style='{StaticResource LabelText}'" >
<xsl:attribute name="Background">#FF3B596E</xsl:attribute>
</xsl:if>
<xsl:attribute name="Background">#FF3B5940</xsl:attribute>
</xsl:element>
</xsl:template>
The style parameter can be either '{StaticResource LabelText}' or '{StaticResource ValueText}' and the background of the border depends on that value.
This if structure fails however, it always draws the FF3B5940 border in my output.xaml file. I call the template like this:
<xsl:call-template name="get-textblock">
<xsl:with-param name="style">{StaticResource LabelText}</xsl:with-param>
</xsl:call-template>
Anyone sees what might be the problem? Thanks.
The line:
<xsl:attribute name="Background">#FF3B5940</xsl:attribute>
is not protected by a conditional check, so it will always execute.
Use this:
<xsl:if test="$style='{StaticResource LabelText}'">
<xsl:attribute name="Background">#FF3B596E</xsl:attribute>
</xsl:if>
<xsl:if test="not($style='{StaticResource LabelText}')">
<xsl:attribute name="Background">#FF3B5940</xsl:attribute>
</xsl:if>
Or xsl:choose
<xsl:choose>
<xsl:when test="$style='{StaticResource LabelText}'">
<xsl:attribute name="Background">#FF3B596E</xsl:attribute>
</xsl:when>
<xsl:otherwise>
<xsl:attribute name="Background">#FF3B5940</xsl:attribute>
</xsl:otherwise>
</xsl:choose>
If you use <xsl:attribute/>
multiple times in the one element context, only last one will be applied to result element.
You can separate <xsl:attribute/>
instructions using <xsl:choose/>
or define one <xsl:attribute/>
before <xsl:if/>
-- it will be used by default:
<xsl:choose>
<xsl:when test="$style='{StaticResource LabelText}'">
<xsl:attribute name="Background">#FF3B596E</xsl:attribute>
</xsl:when>
<xsl:otherwise>
<xsl:attribute name="Background">#FF3B5940</xsl:attribute>
</xsl:otherwise>
</xsl:choose>
or
<xsl:attribute name="Background">#FF3B5940</xsl:attribute>
<xsl:if test="$style='{StaticResource LabelText}'" >
<xsl:attribute name="Background">#FF3B596E</xsl:attribute>
</xsl:if>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With