XML Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - MoreXML Programming
The ASP Free website provides in-depth information on the latest developer tools available from Microsoft. Our cadre of writers, highly experienced industry experts, reveals the best ways to use established technologies as well as new and emerging technologies. Our coverage of Microsoft's development and administration technologies is among the most respected in the IT industry today.

ASP Free and Iron Speed Designer are giving away $5,500+ in FREE licenses. Iron Speed's RAD CASE toolset can save up to 80% of your coding time. One free license per week, one perpetual license per month!
Download and Activate to enter!

Intel® Graphics Performance Analyzers is a powerful tool suite for analyzing and optimizing your games, media, and graphics-intensive applications. Used by some of the best developers on the planet, Intel GPA lets you maximize your app’s performance.


Tutorials
| Forums

Download to Enter
| Contest Rules

DOWNLOAD INTEL® GPA FOR FREE

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old February 1st, 2005, 07:51 AM
horsepower horsepower is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2004
Posts: 31 horsepower User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 14 h 26 m 25 sec
Reputation Power: 8
Question Dynamic array in XSL?

Hi,

lets say I have xml like this:
Code:
<books>
<book>
<author>Stephen King</auhtor>
<name>something</name>
</book>
<book>
<author>Stephen King</auhtor>
<name>something2</name>
</book>
<book>
<author>Agatha Christie</auhtor>
<name>something3</name>
</book>
</books>


If I loop all books with for-each, is it possible to generate somekind of array of authors and number of the books, like in this case Stephen King, 2 Agatha Chistie 1.

In the software I'm doing I need to get output where books are listed according to the author and since the actual data comes from database I don't know the number of different authors and how many books each of them have.

..add here all the "I'm a newbie in XSL/XML.." stuff

And thanks in advance if somebody can help me out with this!

Reply With Quote
  #2  
Old February 3rd, 2005, 11:38 AM
horsepower horsepower is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2004
Posts: 31 horsepower User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 14 h 26 m 25 sec
Reputation Power: 8
Hmm.. maybe I wasn't clear enough..

Well if you have xml (from database) like in my previous post, how would you generate a listing with xsl that would be shown like this:

Author, Number of books
Stephen King, 2
Agatha Christie, 1
..and so on..


Exept that you don't know the names of the authors or how many different authors there are (names shown in this example are just for clearing this out), it has to be figured out with xsl. I don't know how to do that..

There must be somebody who knows how to do this

Reply With Quote
  #3  
Old February 8th, 2005, 01:42 AM
the_z_pilot the_z_pilot is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2005
Location: Nocton near Lincoln
Posts: 66 the_z_pilot User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 21 h 54 m 55 sec
Reputation Power: 8
Yeah!

If you want it how I think you want it, then try this stylesheet below!

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format">

<xsl:template match="/">
<html>
<head>
<title></title>
</head>
<body>
<table border="1">
<tbody>
<tr align="left">
<th>Author</th><th>No. of Books</th>
</tr>
<xsl:for-each select="//book[not(./author = preceding::book/author)]">
<xsl:variable name="auth"><xsl:value-of select="author" /></xsl:variable>
<tr>
<td><xsl:value-of select="author" /></td>
<td><xsl:value-of select="count(//author[text() = $auth]) " /></td>
</tr>
</xsl:for-each>
</tbody>
</table>
</body>
</html>
</xsl:template>

</xsl:stylesheet>

I think it does what you asked.
Enjoy!

Reply With Quote
  #4  
Old February 8th, 2005, 08:31 AM
horsepower horsepower is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2004
Posts: 31 horsepower User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 14 h 26 m 25 sec
Reputation Power: 8
That's perfect!! Thank you, just what I was looking for.

Quote:
Enjoy!
I'm

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreXML Programming > Dynamic array in XSL?


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.

© 2003-2012 by Developer Shed. All rights reserved. DS Cluster 11 - Follow our Sitemap