XML Editor
Sign up for a WebBoard account Sign Up Keyword Search Search More Options... Options
Chat Rooms Chat Help Help News News Log in to WebBoard Log in Not Logged in
Show tree view Topic
Topic Page 1 2 3 4 5 6 7 8 9 Go to previous topicPrev TopicGo to next topicNext Topic
Postnext
Ingram LeedySubject: No Topic
Author: Ingram Leedy
Date: 04 Jan 2006 02:12 PM

Hi, I have a project where I am trying to join data on an element <account> and then provide some grouping and summing.

The idea here is that I want to get the total mailbox size for each respective mailbox, plus give an organizational total and display out on a webpage.

I was thinking of using XSL to perform the query. Below is the example XML file,

<?xml version="1.0"?>
<mydata>
<mailbox>
<displayname>Chris</displayname>
<account>chris.sims</account>
<firstname>Chris</firstname>
<lastname>Sims</lastname>
<upn>chris@sims.com</upn>
</mailbox>
<mailbox>
<displayname>Mark Brown</displayname>
<account>mark.brown</account>
<firstname>Mark</firstname>
<lastname>Brown</lastname>
<upn>mark@brown.com</upn>
</mailbox>
<mailbox>
<displayname>Jim Smith</displayname>
<account>jim.smith</account>
<firstname>Jim</firstname>
<lastname>Smith</lastname>
<upn>jsmith@coloflorida.com</upn>
</mailbox>
<usage>
<account>jim.smith</account>
<size>10</size>
</usage>
<usage>
<account>mark.brown</account>
<size>20</size>
</usage>
<usage>
<account>chris.sims</account>
<size>30</size>
</usage>
</mydata>


Here is an XSL file that I hacked together as a test, but had to use XPATH 2.0 for the grouping. I wasnt able to figure out how to sum the total by group.

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" encoding="UTF-8"/>

<xsl:template match="/">
<xsl:for-each-group select="/mydata/mailbox" group-by="substring-after(upn,'@')">


<xsl:for-each select="current-group()">

<!-- cache the employee's ID -->
<xsl:variable name="id">
<xsl:value-of select="account"/>
</xsl:variable>

<xsl:variable name="size">
<xsl:value-of select="/mydata/usage/size[preceding-sibling::account=$id]"/>
</xsl:variable>

<xsl:value-of select="displayname"/>
<br/>
<xsl:value-of select="substring-after(upn,'@')"/>
<br/>
<xsl:value-of select="$size"/>
<br/>

<br/>
</xsl:for-each>


<xsl:variable name="sizetotal">
<xsl:for-each select="current-group()">
<xsl:variable name="id">
<xsl:value-of select="account"/>
</xsl:variable>
<xsl:value-of select="/mydata/usage/size[preceding-sibling::account=$id]"/>
</xsl:for-each>
</xsl:variable>



<br/>
<xsl:text>Total for </xsl:text>
<xsl:value-of select="current-grouping-key()"/>
<xsl:text> group: </xsl:text>
<xsl:value-of select="count(current-group())"/>
<xsl:text> size: </xsl:text>
<xsl:value-of select="sum(number($sizetotal))"/>


<br/>
</xsl:for-each-group>
</xsl:template>
</xsl:stylesheet>



My question, is there a better way? and/or how do I get the sum of the usage? Thanks!!!

BTW -- eventually this will be used in Microsoft .NET - but seems like will need to use saxon library for xpath 2.0.

Postnext
Tony LavinioSubject: Mailbox XSLT problem
Author: Tony Lavinio
Date: 04 Jan 2006 04:42 PM
I did a little reworking, and I think I've come up with an XSLT 1
program that will do what you want. Your description was a little
vague on exactly how to group, but I'm assuming you want the total
usage by email domain.


Documentmailbox.xsl
Mailbox XSLT

Posttop
Ingram LeedySubject: Mailbox XSLT problem
Author: Ingram Leedy
Date: 05 Jan 2006 02:15 PM
Tony,

Perfect! Even works with xpath 1.0 ! Thank you for your assistance - its a good example to follow.

 
Topic Page 1 2 3 4 5 6 7 8 9 Go to previous topicPrev TopicGo to next topicNext Topic
Download A Free Trial of Stylus Studio 6 XML Professional Edition Today! Powered by Stylus Studio, the world's leading XML IDE for XML, XSLT, XQuery, XML Schema, DTD, XPath, WSDL, XHTML, SQL/XML, and XML Mapping!  
go

Log In Options

Site Map | Privacy Policy | Terms of Use | Trademarks
Stylus Scoop XML Newsletter:
W3C Member
Stylus Studio® and DataDirect XQuery ™are from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2016 All Rights Reserved.