【问题标题】:XSL-FO display text based on percentage of valueXSL-FO 根据值的百分比显示文本
【发布时间】:2017-09-05 10:18:54
【问题描述】:

我有 8 个主要类别。每个类别都有自己的分数,从 0 到 100。 我需要根据该分数的百分比范围显示 5 个不同的文本。

例如: 第 1 类 - 得分为 46% 当分数在这些范围之间时显示这些文本: 文本 1:0-40% 文本 2:41-60% 文本 3:61-80% 文本 4:81-90% 文本 5:91-100%

在这种情况下,我需要显示“文本 2”,因为 46% 属于该范围。

我该怎么做?

我已尝试为此编写代码,但不确定如何在模板部分指定百分比范围。

XSL-FO 文档: <xsl:call-template name="information"> <xsl:with-param name="score" select="//attribute-lines[*/id = 'Path-Brick-Attribute']/*/value-text"/> </xsl:call-template>

XSL 文档中的模板部分:

`<xsl:template name="information">
         <xsl:param name="score"/>
    <xsl:choose>
        <xsl:when test="$score >= 0 and 40 >=">
            <fo:block>
                <xsl:text>
                     Text 1
                </xsl:text>
            </fo:block>
        </xsl:when>
        <xsl:when test="$score &gt;= 41 and &gt;= 60">
            <fo:block>
                <xsl:text>
                    Text 2
                </xsl:text>
            </fo:block>
        </xsl:when>
    </xsl:choose>
</xsl:template>`

【问题讨论】:

标签: xslt xsl-fo value-of


【解决方案1】:

你需要使用的模式是:

<xsl:template name="score-to-label">
    <xsl:param name="score"/>
    <fo:block>
        <xsl:choose>
            <xsl:when test="$score > 90">Text 5</xsl:when>
            <xsl:when test="$score > 80">Text 4</xsl:when>
            <xsl:when test="$score > 60">Text 3</xsl:when>
            <xsl:when test="$score > 40">Text 2</xsl:when>
            <xsl:otherwise>Text 1</xsl:otherwise>
        </xsl:choose>
    </fo:block>
</xsl:template>

这是有效的,因为xsl:choose 在第一个返回 true 的测试中退出。

请注意,这要求$score数字 (0..100) 的形式给出,而不是百分比

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-07-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-06-29
    相关资源
    最近更新 更多