簡體   English   中英

有什么方法可以根據 for-each 中的當前值應用 count() 嗎?

[英]Is there any way to apply a count() depending on the current value in a for-each?

我有一個具有這種結構的 xml 文件


<?xml version='1.0' encoding='UTF-8'?>
<students>
  <student>
    <number>1</number>
    <firstname>Sandrine</firstname>
    <name>BERTIN</name>
    <gender>F</gender>
    <highschool>de la Côte d'Albâtre</highschool>
    <city>Saint-Valéry-en-Caux</city>
    <specialization>Physique chimie</specialization>
  </eleve>

[...]
</students>

最終結果應該是 pdf 文檔,每所高中將與其他信息一起顯示在新頁面上(屬於這所高中的所有學生的列表等......)其中一個信息是性別的學生總數='M'(或'F')。

這是我的代碼的一部分:

  <fo:page-sequence master-reference="book">
    <fo:flow flow-name="xsl-region-body"> 
     <xsl:for-each select="students/student[count(. | key('cityKey',city)[1]) = 1]">
      <xsl:sort select="city" />
             <xsl:for-each select="key('cityKey', city)[count(. | key('highschoolKey',highschool)[1]) = 1]">
              <xsl:sort select="highschool" /> 
               <fo:block break-before="page"><xsl:value-of  select="highschool"/> </fo:block>
               <fo:block> City : <xsl:value-of select="city" /> </fo:block>

              <!-- <fo:block> Number of male students : <xsl:value-of select="count(/students/student[gender='M'])" /> </fo:block> -->



          </xsl:for-each>
        </xsl:for-each>
    </fo:flow>
  </fo:page-sequence>

我想在我的 xsl:for-each 中獲取男學生的 count () 數量並為每個“高中”打印它(我的文檔的每頁/高中上的數字不同)。 但我要么得到所有高中的所有男學生(/students/student[gender='M']),要么什么都沒有。

理想情況下,它看起來像這樣:

**de la Côte d'Albâtre**

City : Saint-Valéry-en-Caux

Number of male students: " "

Number of female students: " "

List of all the student in a Table : [...]

提前致謝

如果您按citystudent進行分組,則:

<xsl:value-of select="count(key('cityKey', city)[gender ='M'])"/>

應該給你當前組中男學生的數量。

--
未經測試,因為您沒有提供完整的示例。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM