2017-09-05 68 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),而不是作爲一個百分比