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

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: 6
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: 6
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: 6
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: 6
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




 Free IT White Papers!
 
How to Present Effectively Online
This white paper offers practical and actionable advice on the key steps that any presenter should consider as they plan and execute a Webinar or online meeting.

 
Open Source Security Myths
Open Source Software (OSS) is computer software whose source code is available to the general public with relaxed or non-existent intellectual property restrictions (or arrangement such as the public domain), and is usually developed with the input of many contributors.

 
Power and Cooling Capacity Management for Data Centers
This paper describes the principles for achieving power and cooling capacity management.

 
Scalable, Fault-Tolerant NAS for Oracle - The Next Generation
For several years NAS has been evolving as a storage alternative for Oracle databases, and for good reason: NAS is quite often the simplest, most cost-effective storage approach for Oracle. Learn about the benefits that HP's approach to scalable NAS brings to Oracle environments in this comprehensive white paper.

 
Understanding Web Application Security Challenges
This white paper discusses many common threats and preventive measures for Web application security, and explains what you can do to help protect your organization.

 

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




© 2003-2010 by Developer Shed. All rights reserved. DS Cluster 7 Hosted by Hostway
For more Enterprise Application Development news, visit eWeek