试图在XSLT中比较两个字符串,结果未如预期

时间:2019-01-23 16:16:57

标签: xslt-1.0

我正在尝试比较XSLT中的两个字符串,并希望将硬编码响应作为结果

我尝试在XSLT中保留if条件,但这为我提供了两个结果

<xsl:template name="variableTransformation">
    <xsl:param name="text"/>
    <xsl:param name="delimiters" select="' /-'"/>

    <xsl:variable name="upper" select="'ABCDEFGHIJKLMNOPQRSTUVWXYZ'"/>
    <xsl:variable name="lower" select="'abcdefghijklmnopqrstuvwxyz'"/>
    <xsl:variable name="nextDelimiter" select="substring(translate($text, translate($text, $delimiters, ''), ''), 1, 1)" />
    <xsl:variable name="string" select="substring-before(concat($text, ' '), substring(concat($nextDelimiter, ' '), 1, 1))" />

    <xsl:value-of select="translate(substring($string, 1, 1), $lower, $upper)"/>
    <xsl:value-of select="translate(substring($string, 2), $upper, $lower)"/>

    <xsl:if test="$nextDelimiter">
        <xsl:value-of select="$nextDelimiter" />
        <xsl:call-template name="variableTransformation">
            <xsl:with-param name="text" select="substring-after($text, $nextDelimiter)"/>
            <xsl:with-param name="delimiters" select="$delimiters"/>
        </xsl:call-template>
    </xsl:if>
    <xsl:if test="$text='SELF EMPLOYED'">
            <xsl:value-of select="'Self-Employed'"></xsl:value-of>
    </xsl:if>
    <xsl:if test="$text='SKILL TRADE'">
        <xsl:value-of select="'Skilled Trade'"></xsl:value-of>
    </xsl:if>
</xsl:template>

输入:1.政府2.学生3.家庭主妇4.专业5.自雇6.服务/零售7.技能贸易8.失业9.其他

预期:

Government
Student
Homemaker
Professional 
Self-Employed
Service/Retail
Skilled Trade
Unemployed
Other

实际:

Government
Student
Homemaker
Professional 
Self EmployedSelf-Employed
Service/Retail
Skill TradeSkilled Trade
Unemployed
Other

0 个答案:

没有答案