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
Conferences Close Tree View
+ Stylus Studio Feature Requests (1192)
+ Stylus Studio Technical Forum (14621)
+ Website Feedback (249)
- XSLT Help and Discussion (7625)
-> + Use of before and after string (3) Sticky Topic
-> - How do I substitute element ty... (1)
-> + How does one add working days ... (4)
-> - Help, I have existing XLT and... (1)
-> + Need help on XSLT issue - (2)
-> + EDI to XML Conversion (7)
-> - XML To JSON Conversion using X... (1)
-> + Formatting Paragraphs to same ... (2)
-> - Grouping of records (1)
-> + Problems with xsd 1.1 (4)
-> + XML to HL7 mapping (3)
-> + XSLT 3 and Iterate (2)
-> + XSL-FO to PDF preview (3)
-> + java.lang.RuntimeException: Er... (2)
-> + Create Acroforms with Stylus X... (2)
-> + How to change XSLT parameter s... (3)
-> + how to change format of the da... (2)
-> + Search "Next 8 Results " doesn... (2)
-> - Support for Git (1)
-> + newbee (8)
-- [1-20] [21-40] [41-60] Next
+ XQuery Help and Discussion (2017)
+ Stylus Studio FAQs (159)
+ Stylus Studio Code Samples & Utilities (364)
+ Stylus Studio Announcements (113)
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.

   
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.