XSLT:如果检查参数值

Mat*_*ias 4 xslt

下面是xslt中的代码(我删除了不相关的部分,get-textblock更长,并且有很多参数都正确传递):

<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>
Run Code Online (Sandbox Code Playgroud)

style参数可以是'{StaticResource LabelText}'或'{StaticResource ValueText}',边框的背景取决于该值.

但是,如果结构失败,它总是在我的output.xaml文件中绘制FF3B5940边框.我这样称呼模板:

<xsl:call-template name="get-textblock">
    <xsl:with-param name="style">{StaticResource LabelText}</xsl:with-param>                    
</xsl:call-template>
Run Code Online (Sandbox Code Playgroud)

有谁看到可能是什么问题?谢谢.

Way*_*ett 7

这条线:

<xsl:attribute name="Background">#FF3B5940</xsl:attribute>
Run Code Online (Sandbox Code Playgroud)

不受条件检查的保护,因此它将始终执行.

用这个:

<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>
Run Code Online (Sandbox Code Playgroud)

要么 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>
Run Code Online (Sandbox Code Playgroud)