2017-09-05 69 views
0

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

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

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

我该怎么做?

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

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

模板部分:

`<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>` 
+2

请在您的XSLT中显示您的XML和目前为止的处理方式。 –

+1

https://www.w3.org/TR/xslt/#section-Conditional-Processing-with-xsl:choose –

+1

http://stackoverflow.com/help/someone-answers –

回答

2

你需要使用的模式是:

<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),而不是作为一个百分比