XSLT:'xsl:when'条件和'string-length'返回

时间:2015-08-12 08:56:41

标签: xslt

当我写这篇文章时,我的XSLT文件正常工作:

<xsl:for-each select="TestLogItem[contains(Message, 'TestCase')]">
    <xsl:sort select="substring(Message, 23, 3)" data-type="number"/>
    <!-- function to order the number of the TestCases -->
    <xsl:variable name="bingo" select="substring(Message, 19, 7)"/>

但是当我尝试根据Message的长度放入一个条件时,变量“bingo”会改变,它不起作用:

<xsl:for-each select="TestLogItem[contains(Message, 'TestCase')]">
    <xsl:sort select="substring(Message, 23, 3)" data-type="number"/>
    <!-- function to order the number of the TestCases -->
    <xsl:variable name="size" select="string-length(Message)"/>
    <!-- creation of a variable to select the number of the TestCase -->
    <xsl:choose>
        <xsl:when test="$size=46">
            <xsl:variable name="bingo" select="substring(Message, 19, 7)"/>
        </xsl:when>
        <xsl:when test="$size=47">
            <xsl:variable name="bingo" select="substring(Message, 19, 8)"/>
        </xsl:when> 
    </xsl:choose>

我测试了变量“size”,我知道它有效。所以我猜问题是在“何时”的情况下。

1 个答案:

答案 0 :(得分:1)

您需要使用<xsl:variable ...><xsl:choose>...</xsl:choose></xsl:variable>,例如

<xsl:variable name="bingo">
                    <xsl:choose>
                        <xsl:when test="$size=46">
                             <xsl:value-of select="substring(Message, 19, 7)"/>
                        </xsl:when>
                        <xsl:when test="$size=47">
                            <xsl:value-of select="substring(Message, 19, 8)"/>
                        </xsl:when> 
                    </xsl:choose>
</xsl:variable>

或许<xsl:variable name="bingo" select="substring(Message, 19, -39 + $size)"/>