首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >组和计数数据

组和计数数据
EN

Stack Overflow用户
提问于 2020-03-30 05:41:58
回答 1查看 49关注 0票数 0

我正在努力根据考试复习中的不同步骤来计算每个学生评估的点数。学生考试评价有多层次的应用评价、笔试、小组面试、面试。我在每个级别上都找到了基于性别的计数。

xml:

代码语言:javascript
复制
<xd:StudentData xmlns:xd="urn:com.student.report/student_test">
<xd:StudentRecord>
<xd:StudentRequisition xd:Descriptor="1858 Economics"></xd:StudentRequisition>
<xd:StudentStatus xd:Descriptor="Pass"></xd:StudentStatus>
<xd:StudentApplication xd:Descriptor="1858 Economics"></xd:StudentApplication>
<xd:StudentID>S-1</xd:StudentID>
<xd:Gender xd:Descriptor="Male"></xd:Gender>
<xd:StudentDate>2020-01-01-12:00</xd:StudentDate>
<xd:Total_Score>75</xd:Total_Score>
<xd:ProfileStudentTestGroup>
<xd:StudentTest xd:Descriptor="Student Evaluation"></xd:StudentTest>
<xd:StudentTest_Status xd:Descriptor="Pass"></xd:StudentTest_Status>
<xd:StudentTest_Date>2020-01-31-12:00</xd:StudentTest_Date>
<xd:StudentTest_Result_Score>75</xd:StudentTest_Result_Score>
</xd:ProfileStudentTestGroup>
</xd:StudentRecord>
<xd:StudentRecord>
<xd:StudentRequisition xd:Descriptor="1500 Social Service"></xd:StudentRequisition>
<xd:StudentStatus xd:Descriptor="Fail"></xd:StudentStatus>
<xd:StudentApplication xd:Descriptor="1500 Social Service"></xd:StudentApplication>
<xd:StudentID>S-3</xd:StudentID>
<xd:Gender xd:Descriptor="Female"></xd:Gender>
<xd:StudentDate>2020-01-01-12:00</xd:StudentDate>
<xd:Total_Score>65</xd:Total_Score>
<xd:ProfileStudentTestGroup>
<xd:StudentTest xd:Descriptor="Student Evaluation"></xd:StudentTest>
<xd:StudentTest_Status xd:Descriptor="Pass"></xd:StudentTest_Status>
<xd:StudentTest_Date>2020-01-31-12:00</xd:StudentTest_Date>
<xd:StudentTest_Result_Score>65</xd:StudentTest_Result_Score>
</xd:ProfileStudentTestGroup>
</xd:StudentRecord>
<xd:StudentRecord>
<xd:StudentRequisition xd:Descriptor="1500 Social Service"></xd:StudentRequisition>
<xd:StudentStatus xd:Descriptor="Fail"></xd:StudentStatus>
<xd:StudentApplication xd:Descriptor="1500 Social Service"></xd:StudentApplication>
<xd:StudentID>S-4</xd:StudentID>
<xd:Gender xd:Descriptor="Female"></xd:Gender>
<xd:StudentDate>2020-01-01-12:00</xd:StudentDate>
<xd:Total_Score>67</xd:Total_Score>
<xd:ProfileStudentTestGroup>
<xd:StudentTest xd:Descriptor="Student Evaluation"></xd:StudentTest>
<xd:StudentTest_Status xd:Descriptor="Pass"></xd:StudentTest_Status>
<xd:StudentTest_Date>2020-01-31-12:00</xd:StudentTest_Date>
<xd:StudentTest_Result_Score>67</xd:StudentTest_Result_Score>
</xd:ProfileStudentTestGroup>
</xd:StudentRecord>
<xd:StudentRecord>
<xd:StudentRequisition xd:Descriptor="1858 Economics"></xd:StudentRequisition>
<xd:StudentStatus xd:Descriptor="Pass"></xd:StudentStatus>
<xd:StudentApplication xd:Descriptor="1858 Economics"></xd:StudentApplication>
<xd:StudentID>S-7</xd:StudentID>
<xd:Gender xd:Descriptor="Male"></xd:Gender>
<xd:StudentDate>2020-01-01-12:00</xd:StudentDate>
<xd:Total_Score>85</xd:Total_Score>
<xd:ProfileStudentTestGroup>
<xd:StudentTest xd:Descriptor="Student Evaluation"></xd:StudentTest>
<xd:StudentTest_Status xd:Descriptor="Pass"></xd:StudentTest_Status>
<xd:StudentTest_Date>2020-01-31-12:00</xd:StudentTest_Date>
<xd:StudentTest_Result_Score>85</xd:StudentTest_Result_Score>
</xd:ProfileStudentTestGroup>
</xd:StudentRecord>
</xd:StudentData>

xslt:

代码语言:javascript
复制
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet exclude-result-prefixes="xsl" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    version="2.0" xmlns:xsd="http://www.w3.org/2001/XMLSchema"
    xmlns:xd="urn:com.student.report/student_test">

<xsl:iterate select="StudentData/StudentRecord">

    <xsl:param name="male_pass_count" select="0.00" as="xs:integer"/>
    <xsl:param name="male_fail_count" select="0.00" as="xs:integer"/>
    <xsl:param name="female_pass_count" select="0.00" as="xs:integer"/>
    <xsl:param name="female_fail_count" select="0.00" as="xs:integer"/>
    <xsl:param name="StudentTest" select="{/xd:StudentTest/@xd:Descriptor}" as="xs:string"/>

    <xsl:choose>

    <xsl:when test="{/xd:Gender/@xd:Descriptor} = 'Male'">

        <xsl:if test="{/xd:StudentTest_status/@xd:Descriptor} = 'Pass'">
        <xsl:with-param name="male_pass_count" select="$male_pass_count + 1"/>
        </xsl:if>

        <xsl:if test="{/xd:StudentTest_status/@xd:Descriptor} = 'Fail'">
        <xsl:with-param name="male_fail_count" select="$male_fail_count + 1"/>
        </xsl:if>

    </xsl:when> 

    <xsl:when test="{/xd:Gender/@xd:Descriptor} = 'Female'">

        <xsl:if test="{/xd:StudentTest_status/@xd:Descriptor} = 'Pass'">
        <xsl:with-param name="female_pass_count" select="$female_pass_count + 1"/>
        </xsl:if>

        <xsl:if test="{/xd:StudentTest_status/@xd:Descriptor} = 'Fail'">
        <xsl:with-param name="female_fail_count" select="$female_fail_count + 1"/>
        </xsl:if>

    </xsl:when> 

    </xsl:choose>

<xsl:on-completion>

    <student id="{$StudentTest}">
        <male_pass_count>{$male_pass_count}</male_pass_count>
        <male_fail_count>{$male_fail_count}</male_fail_count>
        <female_pass_count>{$female_pass_count}</female_pass_count>
        <female_fail_count>{$female_fail_count}</female_fail_count>

    </student>

</xsl:on-completion>

</xsl:iterate>

输出:

代码语言:javascript
复制
StudentRequisition  StudentTest             MalePass    MaleFail    FemalePass  FemaleFail
1858 Economics      Application evaluation  22          0           10          0
1858 Economics      Interview               6           11          0           5
1858 Economics      Written Test            2           0           2           0
1500 Social Service Application evaluation  10          12          10          12
1500 Social Service Interview               0           0           0           0
1500 Social Service Written Test            0           0           0           0
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-03-30 15:32:02

如果您使用XSLT 3处理器(正如您使用xsl:iterate所指示的那样),您可以在申请和我认为的测试中使用带有组合分组键的for-each-group

代码语言:javascript
复制
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:xs="http://www.w3.org/2001/XMLSchema"
    xpath-default-namespace="urn:com.student.report/student_test"
    xmlns:xd="urn:com.student.report/student_test"
    expand-text="yes"
    exclude-result-prefixes="#all"
    version="3.0">

  <xsl:output indent="yes" method="html" html-version="5"/>

  <xsl:template match="/">
      <html>
          <head>
              <title>Grouping example</title>
          </head>
          <body>
              <xsl:apply-templates/>
          </body>
      </html>
  </xsl:template>

  <xsl:template match="StudentData">
      <table>
          <thead>
              <tr>
                  <th>Student Requisition</th>
                  <th>Student Test</th>
                  <th>Male Pass</th>
                  <th>Male Fail</th>
                  <th>Female Pass</th>
                  <th>Female Fail</th>
              </tr>
          </thead>
          <tbody>
              <xsl:for-each-group select="StudentRecord" composite="yes" group-by="StudentRequisition/@xd:Descriptor, ProfileStudentTestGroup/StudentTest/@xd:Descriptor">
                  <tr>
                      <td>{current-grouping-key()[1]}</td>
                      <td>{current-grouping-key()[2]}</td>
                      <td>{count(current-group()[Gender/@xd:Descriptor = 'Male'][ProfileStudentTestGroup/StudentTest_Status[@xd:Descriptor = 'Pass']])}</td>
                      <td>{count(current-group()[Gender/@xd:Descriptor = 'Male'][ProfileStudentTestGroup/StudentTest_Status[@xd:Descriptor = 'Fail']])}</td>
                      <td>{count(current-group()[Gender/@xd:Descriptor = 'Female'][ProfileStudentTestGroup/StudentTest_Status[@xd:Descriptor = 'Pass']])}</td>
                      <td>{count(current-group()[Gender/@xd:Descriptor = 'Female'][ProfileStudentTestGroup/StudentTest_Status[@xd:Descriptor = 'Fail']])}</td>
                  </tr>
              </xsl:for-each-group>
          </tbody>
      </table>
  </xsl:template>

</xsl:stylesheet>

https://xsltfiddle.liberty-development.net/93dFepD

如果您使用XSLT 2处理器(它不支持组合分组键),那么要么将这两个值连接起来,要么嵌套两个for-each-group指令。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/60924671

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档