【发布时间】:2017-11-26 17:24:45
【问题描述】:
有人可以按照以下要求引导我朝着正确的方向前进吗?我正在尝试为每个组添加页脚。页脚只需要计算每个组中具有相同 Student_Status 的记录。
下面是 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>
下面是 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> </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>
下面是当前输出
2345,Full
7891,Half
4568,Full
9897,Full
Count 4
我正在尝试让以下输出为每个 Student_Status 提供一个页脚,并计算每个组中的记录数。
2345,Full
4568,Full
9897,Full
Count 3
7891,Half
Count 1
非常感谢任何帮助!
【问题讨论】: