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
Dogmar SSubject: Count Records?
Author: Dogmar S
Date: 19 Apr 2006 12:37 PM
Hello,

I have the following:

type1
type2
type3

and I would like to be able to display the number of entries of each type. The XML is very simple:

<Rows>
<Row>
<Status>type2</Status>
</Row>
<Row>
<Status>type1</Status>
</Row>
<Row>
<Status>type3</Status>
</Row>
<Row>
<Status>type2</Status>
</Row>
<Row>
<Status>type3</Status>
</Row>
<Row>
<Status>type3</Status>
</Row>
<Row>
<Status>type1</Status>
</Row>
<Row>
<Status>type2</Status>
</Row>
<Row>
<Status>type3</Status>
</Row>
</Rows>


It seems easy, but I am just not getting it to work. Thank you very much.

DH

Postnext
Minollo I.Subject: Count Records?
Author: Minollo I.
Date: 19 Apr 2006 12:45 PM
Do you mean like in:
count(//Row[Status='type1'])

Postnext
Dogmar SSubject: Count Records?
Author: Dogmar S
Date: 19 Apr 2006 01:10 PM
Thank you. Yes, I have tried that. I think maybe I was not clear before. If I do that, then I get the same value for each one. What would be nice is to have like this:

type1 4
type2 3
type3 6

so that each has the value beside it. When I tried it with just the count, I did not know how to get the right count next to the right item. Thank you again.

DH

Postnext
Minollo I.Subject: Count Records?
Author: Minollo I.
Date: 19 Apr 2006 01:20 PM
So the "typeX" names change dynamically and you need to retrieve them from the XML documents.

In that case you'll have to first create an outer looping structure that avoids duplicates and retrieves the single "typeX" items (easy to do if you are using XQuery), and then an nested computation that retrieves the count. If you search the forum for "grouping" or "distinct", you should find clues about how to do that.

Minollo

Postnext
Dogmar SSubject: Count Records?
Author: Dogmar S
Date: 19 Apr 2006 04:01 PM
hmm...

Well, I got the following:

<xsl:for-each select="/Rows/Row[generate-id() = generate-id(key('names', Status)[1])]">
<xsl:variable name="name" select="Status"/>
<tr>
<td>
<xsl:value-of select="Status"/>
</td>
<td>
<xsl:value-of select="count(//Row)"/>
</td>
</tr>
</xsl:for-each>

and that gives me a distinct (1 entry per status), but also counts all of the items regardless of status and puts that number beside each one. Any help to finish this out, I would appreciate. Thank you very much.

DSH

Postnext
Ivan PedruzziSubject: Count Records?
Author: Ivan Pedruzzi
Date: 19 Apr 2006 04:31 PM

<xsl:for-each select="/Rows/Row[generate-id() = generate-id(key('names', Status)[1])]">
<xsl:variable name="status" select="Status"/>
<tr>
<td>
<xsl:value-of select="Status"/>
</td>
<td>
<xsl:value-of select="count(/Rows/Row[Status = $status])"/>
</td>
</tr>
</xsl:for-each>


Ivan Pedruzzi
Stylus Studio Team

Posttop
Dogmar SSubject: Count Records?
Author: Dogmar S
Date: 19 Apr 2006 04:34 PM
ahh...Thank you very much!

DSH

 
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-2011 All Rights Reserved.