<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
	<xsl:output method="html" encoding="UTF-8" indent="yes"/>
	<xsl:template match="/">
		<html>
			<body>
				<table border="1">
					<tr>
						<th colspan="3">By Groups</th>
					</tr>
					<tr>
						<th>Group</th>
						<th>Count</th>
						<th>Size</th>
					</tr>
					<xsl:apply-templates select="mydata/mailbox[substring-after(upn, '@')]" mode="group"/>
				</table>
				<table border="1">
					<tr>
						<th colspan="3">By Users</th>
					</tr>
					<tr>
						<th>User</th>
						<th>Email</th>
						<th>Size</th>
					</tr>
					<xsl:apply-templates select="mydata/mailbox"/>
				</table>
			</body>
		</html>
	</xsl:template>
	<xsl:template match="mailbox">
		<xsl:variable name="user" select="account"/>
		<tr>
			<td>
				<xsl:value-of select="displayname"/>
			</td>
			<td>
				<xsl:value-of select="upn"/>
			</td>
			<td>
				<xsl:value-of select="sum(/mydata/usage/size[../account = $user])"/>
			</td>
		</tr>
	</xsl:template>
	<xsl:template match="mailbox" mode="group">
		<xsl:variable name="this" select="substring-after(upn, '@')"/>
		<xsl:if test="not(preceding-sibling::mailbox/upn[substring-after(., '@') = $this])">
			<xsl:call-template name="group">
				<xsl:with-param name="group" select="$this"/>
			</xsl:call-template>
		</xsl:if>
	</xsl:template>
	<xsl:template name="group">
		<xsl:param name="group"/>
		<tr>
			<td>
				<xsl:value-of select="$group"/>
			</td>
			<td>
				<xsl:value-of select="count(/mydata/mailbox[substring-after(upn, '@') = $group])"/>
			</td>
			<td>
				<xsl:value-of select="sum(/mydata/usage/size[../account = /mydata/mailbox/account[substring-after(../upn, '@') = $group]])"/>
			</td>
		</tr>
	</xsl:template>
</xsl:stylesheet><!-- Stylus Studio meta-information - (c) 2004-2005. Progress Software Corporation. All rights reserved.
<metaInformation>
<scenarios ><scenario default="yes" name="Scenario1" userelativepaths="yes" externalpreview="no" url="mailbox.xml" htmlbaseurl="" outputurl="" processortype="internal" useresolver="yes" profilemode="0" profiledepth="" profilelength="" urlprofilexml="" commandline="java.exe jd.xml.xslt.Stylesheet %1 %2 >%3" additionalpath="" additionalclasspath="C:\j\lib\jdxslt.jar" postprocessortype="none" postprocesscommandline="" postprocessadditionalpath="" postprocessgeneratedext="" validateoutput="no" validator="internal" customvalidator=""/></scenarios><MapperMetaTag><MapperInfo srcSchemaPathIsRelative="yes" srcSchemaInterpretAsXML="no" destSchemaPath="" destSchemaRoot="" destSchemaPathIsRelative="yes" destSchemaInterpretAsXML="no" ><SourceSchema srcSchemaPath="mailbox.xml" srcSchemaRoot="mydata" AssociatedInstance="" loaderFunction="document" loaderFunctionUsesURI="no"/></MapperInfo><MapperBlockPosition><template match="/"><block path="xsl:apply&#x2D;templates" x="287" y="0"/></template></MapperBlockPosition><TemplateContext></TemplateContext><MapperFilter side="source"></MapperFilter></MapperMetaTag>
</metaInformation>
-->