У меня есть документ xml, который я пытаюсь преобразовать в другой документ xml с группировкой и количеством. Я пробовал текст, как я использовал его в прошлом, и все работает, как ожидалось, но я пытаюсь преобразовать в xml и не вижу результатов, как ожидалось.
Ошибка: префикс пространства имен 'xd' не был объявлен
xml:
<?xml version="1.0" encoding="UTF-8"?>
<xd:StudentData xmlns:xd="urn:com.student.report/student_test">
<xd:StudentRecord>
<xd:StudentRequisition xd:Descriptor="1858 Economics"/>
<xd:StudentStatus xd:Descriptor="Pass"/>
<xd:StudentApplication xd:Descriptor="1858 Economics"/>
<xd:StudentID>S-1</xd:StudentID>
<xd:Gender xd:Descriptor="Male"/>
<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_Status xd:Descriptor="Pass"/>
<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:StudentStatus xd:Descriptor="Fail"/>
<xd:StudentApplication xd:Descriptor="1500 Social Service"/>
<xd:StudentID>S-3</xd:StudentID>
<xd:Gender xd:Descriptor="Female"/>
<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_Status xd:Descriptor="Pass"/>
<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:StudentStatus xd:Descriptor="Fail"/>
<xd:StudentApplication xd:Descriptor="1500 Social Service"/>
<xd:StudentID>S-4</xd:StudentID>
<xd:Gender xd:Descriptor="Female"/>
<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_Status xd:Descriptor="Pass"/>
<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:StudentStatus xd:Descriptor="Pass"/>
<xd:StudentApplication xd:Descriptor="1858 Economics"/>
<xd:StudentID>S-7</xd:StudentID>
<xd:Gender xd:Descriptor="Male"/>
<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_Status xd:Descriptor="Pass"/>
<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:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:math="http://www.w3.org/2005/xpath-functions/math"
xmlns:map="http://www.w3.org/2005/xpath-functions/map"
xmlns:array="http://www.w3.org/2005/xpath-functions/array"
xmlns:xd="urn:com.student.report/student_test"
exclude-result-prefixes="#all"
version="3.0">
<xsl:mode on-no-match="shallow-copy"/>
<xsl:output method="xml" indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:template match="/*">
<root>
<xsl:for-each-group select="StudentRecord" composite="yes" group-by="StudentRequisition/@xd:Descriptor, ProfileStudentTestGroup/StudentTest/@xd:Descriptor">
<StudentRequisition>
<xsl:text>{current-grouping-key()[1]}</xsl:text>
</StudentRequisition>
<StudentTest>
<xsl:text>{current-grouping-key()[2]}</xsl:text>
</StudentTest>
<MPass>
<xsl:text>{count(current-group()[Gender/@xd:Descriptor = 'Male'][ProfileStudentTestGroup/StudentTest_Status[@xd:Descriptor = 'Pass']])}</xsl:text>
</MPass>
</xsl:for-each-group>
</root>
</xsl:template>
</xsl:stylesheet>
выход:
<root>
<StudentRequisition>1858 Economics</StudentRequisition>
<StudentTest>Student Evaluation</StudentTest>
<MPass>1</MPass>
</root>