Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old May 10th, 2006, 10:59 AM
Registered User
 
Join Date: May 2006
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to daula7
Default xslt help desperately needed

I have a xml that looks like:

---snip---

<dts>
<output>
<total name="test_t">
  <total name="cState">
    <total name="date_range">
      <value >00-06 </value>
      <count>21</count>
    </total>
    <total name="date_range">
      <value >07-12 </value>
      <count>26</count>
    </total>
    <total name="date_range">
      <value>13-24 </value>
      <count>34</count>
    </total>
    <value>AK</value>
    <count>81</count>
  </total>
  <total name="cState">
    <total name="date_range">
      <value >00-06 </value>
      <count>50</count>
    </total>
    <total name="date_range">
      <value >07-12 </value>
      <count>10</count>
    </total>
    <total name="date_range">
      <value>13-24 </value>
      <count>40</count>
    </total>
    <value>AR</value>
    <count>100</count>
  </total>
  .
  .
  .
</total>
</output>
</dts>

---snip----

I'm seeeking help in using xslt for transformation/ retrieve data such that, to display the sum of "count" by "date_range" for all states.
For instance:

00-06 : 21
00-06 : 50
Total : 71

07-12 : 26
07-12 : 10
Total : 36

et cetera...

Any help and recommendations are highly anticipated.

Thanks

daula
 
Old May 10th, 2006, 11:13 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

This is a standard grouping problem. In XSLT 2.0 it's simply:

<xsl:for-each-group select="//total[@name='date_range']"
  group-by="value">
  <xsl:for-each select="current-group()">
    <tr>
      <td><xsl:value-of select="value"/></td>
      <td><xsl:value-of select="count"/></td>
    </tr>
  </xsl:for-each>
  <tr>
    <td>Total</td>
    <td><xsl:value-of select="sum(current-group()/count)"/></td>
  </tr>
</xsl:for-each>

If you're stuck with XSLT 1.0 then grouping is much harder, but there's plenty of advice at http://www.jenitennison.com/xslt/grouping (or in any decent XSLT textbook)

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old May 10th, 2006, 12:09 PM
Registered User
 
Join Date: May 2006
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to daula7
Default

Thanks for you input.
Unfortunetly, I'm using XSLT 1.0...
I browsed on the grouping topics in the link you posted but I couldn't figure a solution. Also, I being a newbie could be a big factor too.
Could there be a solution for this problem using XSLT 1.0??
Or will I need to reformat/ re-arrange the xml file??
Thanks again.

daula






Similar Threads
Thread Thread Starter Forum Replies Last Post
Help needed on XSLT baruprasad XSLT 8 October 21st, 2008 09:03 AM
help needed in XSLT ddeokarb XSLT 1 November 22nd, 2007 10:41 AM
XSLT Help Needed JZen XSLT 9 February 22nd, 2007 04:27 AM
help needed regarding xslt pradeep.mallavarapu XSLT 1 April 19th, 2006 05:58 AM
help needed for xslt rameshnarayan XSLT 2 September 19th, 2005 03:58 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.