2017-11-26 4 views
0

誰かが私の下にある正しい方向に私を導くことができますか?私は各グループのフッターを追加しようとしています。フッターは、同じStudent_Statusを持つ各グループのレコードの数を持つだけです。以下は XSLTバージョン2.0-レコード数が各グループのフッター

以下は、私は以下を取得しようとしている

2345,Full 
    7891,Half 
    4568,Full 
    9897,Full 
    Count 4 

電流出力があるXSLT

 <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema" version="2.0"> 

      <xsl:output method='text' indent="no"/> 
      <xsl:variable name="separator"><xsl:text>,</xsl:text></xsl:variable> 
      <xsl:variable name="newLine"><xsl:text>&#10;</xsl:text></xsl:variable> 

       <xsl:template match="Record"> 
        <xsl:for-each-group select="Student" group-by="concat(Student_ID, Student_Status)"> 
         <xsl:for-each select="current-group()"> 
          <Student_ID><xsl:value-of select="Student_ID"/></Student_ID><xsl:value-of select="$separator"/> 
          <Student_Status><xsl:value-of select="Student_Data/Student_Hours/Student_Status"/></Student_Status> 
          <xsl:value-of select="$newLine"/>  
         </xsl:for-each> 
        </xsl:for-each-group> 
        <!--Footer--> 
        <Count>Count </Count> <xsl:value-of select="count(Student/Student_ID)"/> 
        <!--Footer--> 
       </xsl:template> 
     </xsl:stylesheet> 

XML以下

<Record>  
<Student> 
    <Student_ID>2345</Student_ID> 
    <Student_Data> 
     <Student_Hours> 
      <Student_Status>Full</Student_Status> 
     </Student_Hours> 
    </Student_Data> 
</Student> 
<Student> 
    <Student_ID>7891</Student_ID> 
    <Student_Data> 
     <Student_Hours> 
      <Student_Status>Half</Student_Status> 
     </Student_Hours> 
    </Student_Data> 
</Student> 
<Student> 
    <Student_ID>4568</Student_ID> 
    <Student_Data> 
     <Student_Hours> 
      <Student_Status>Full</Student_Status> 
     </Student_Hours> 
    </Student_Data> 
</Student> 
<Student> 
    <Student_ID>9897</Student_ID> 
    <Student_Data> 
     <Student_Hours> 
      <Student_Status>Full</Student_Status> 
     </Student_Hours> 
    </Student_Data> 
</Student> 

されていますのためのフッターを持つ出力各Student_Status、各グループのレコードの数を持っています。

2345,Full 
    4568,Full 
    9897,Full 
    Count 3 
    7891,Half 
    Count 1 

ご協力いただきありがとうございます。

答えて

2

、あなただけの状態のグループとはcurrent-group()アイテムを数える場合は、あなたが記述の出力を取得する必要が:

  <xsl:template match="Record"> 
       <xsl:for-each-group select="Student" group-by="Student_Data/Student_Hours/Student_Status"> 
        <xsl:for-each select="current-group()"> 
         <Student_ID><xsl:value-of select="Student_ID"/></Student_ID><xsl:value-of select="$separator"/> 
         <Student_Status><xsl:value-of select="current-grouping-key()"/></Student_Status> 
         <xsl:value-of select="$newLine"/>  
        </xsl:for-each> 
        <xsl:value-of select="'Count:', count(current-group()), $newLine"/> 
       </xsl:for-each-group> 
      </xsl:template> 

http://xsltransform.net/pNmBy2d/1

+0

これは完璧です!ありがとうございました!! –

関連する問題