Muenchian grouping, counting number of groups

delldude1989

New Member
Am using muenchian grouping to group subjets and grades as per students. I can get count for number of subjects opted by each student. But I could not get count of number of students.Input XML\[code\]<data> <school>MIT Kindergarden</school> <year>2013</year> <batch>B</batch> <result> <student>ABC</student> <id>001</id> <subject>ALG</subject> <grade>C</grade> </result> <result> <student>ABC</student> <id>001</id> <subject>HIS</subject> <grade>B</grade> </result> <result> <student>ABC</student> <id>001</id> <subject>PHY</subject> <grade>B</grade> </result> <result> <student>XYZ</student> <id>002</id> <subject>ALG</subject> <grade>C</grade> </result> <result> <student>XYZ</student> <id>002</id> <subject>ALG</subject> <grade>A</grade> </result> <result> <student>XYZ</student> <id>002</id> <subject>PHY</subject> <grade>B</grade> </result> <result> <student>PQR</student> <id>003</id> <subject>ALG</subject> <grade>B</grade> </result> <result> <student>PQR</student> <id>003</id> <subject>HIS</subject> <grade>B</grade> </result></data>\[/code\]XSLT \[code\]<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl"> <xsl:output method="xml" indent="yes"/> <xsl:key name="group-by-id" match="data/result" use="id" /> <xsl:template match="/"> <schoolresult> <schoolname> <xsl:value-of select="data/school" /> </schoolname> <resultyear> <xsl:value-of select="data/year" /> </resultyear> <batch> <xsl:value-of select="data/batch" /> </batch> <totalstudent>??</totalstudent> <xsl:for-each select="data/result[generate-id() = generate-id(key('group-by-id', id)[1])]"> <student> <info> <name> <xsl:value-of select="student" /> </name> <id> <xsl:value-of select="id" /> </id> <subjectsopted> <xsl:value-of select="count(. | key('group-by-id', id))" /> </subjectsopted> </info> <xsl:for-each select="key('group-by-id', id)"> <subject> <name> <xsl:value-of select="subject" /> </name> <grade> <xsl:value-of select="grade" /> </grade> </subject> </xsl:for-each> </student> </xsl:for-each> </schoolresult> </xsl:template></xsl:stylesheet>\[/code\]Output XML\[code\]<schoolresult> <schoolname>MIT Kindergarden</schoolname> <resultyear>2013</resultyear> <batch>B</batch> <studentscount>??</studentscount> <student> <info> <name>ABC</name> <id>001</id> <subjectsopted>3</subjectsopted> </info> <subject> <name>ALG</name> <grade>C</grade> </subject> <subject> <name>HIS</name> <grade>B</grade> </subject> <subject> <name>PHY</name> <grade>B</grade> </subject> </student> <student> <info> <name>XYZ</name> <id>002</id> <subjectsopted>3</subjectsopted> </info> <subject> <name>ALG</name> <grade>C</grade> </subject> <subject> <name>ALG</name> <grade>A</grade> </subject> <subject> <name>PHY</name> <grade>B</grade> </subject> </student> <student> <info> <name>PQR</name> <id>003</id> <subjectsopted>2</subjectsopted> </info> <subject> <name>ALG</name> <grade>B</grade> </subject> <subject> <name>HIS</name> <grade>B</grade> </subject> </student></schoolresult>\[/code\]
 
Back
Top