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 December 9th, 2010, 01:00 AM
Registered User
 
Join Date: Dec 2010
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default How to produce this output in XSLT 1.0

Hi,

Newbie here :)

From this XML file,
http://pages.infinit.net/plague/top500.xml

How do I go about producing an XSLT file that will produce this output:
http://pages.infinit.net/plague/countrystats.png

I'm not asking a complete XSLT, just point me in the right direction, please. I expect use of the Muench algorithm and xsl:key but my attempts have been unsuccessful.

So far I'm a long way to go. Here's my XSLT file in progress. It correctly displays the amount of entries (sites) each country appears in, but doesn't eliminate repeats, and doesn't sort! And I haven't even thought about how I'm gonna implement the share %.

Thanks! :)


<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:top500="http://www.top500.org/xml/top500/1.0">
<xsl:output method="html" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:key name="sites-by-country" match="top500:site" use="top500:country"/>
<xsl:template match="/top500:list">
<html>
<head>
<title>ALL COUNTRIES IN TOP 500</title>
</head>
<body>
<table style="text-align:left">
<tr style="background-color=7777FF">
<th width="150">Countries</th>
<th>Count</th>
<th>Share %</th>
</tr>
<xsl:for-each select="top500:site/top500:country">
<xsl:sort select="top500:country"/>
<tr>
<td>
<xsl:value-of select="."/>
</td>
<td>
<xsl:value-of select="count(//top500:site[top500:country=current()])"/>
</td>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>

</xsl:stylesheet>
 
Old December 9th, 2010, 04:34 AM
samjudson's Avatar
Friend of Wrox
 
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
Default

You've got everything right you just need to change your for-each loop to actually use the key you've created.

The best page on Muenchian grouping is here:

http://www.jenitennison.com/xslt/gro...muenchian.html

Code:
               <xsl:for-each select="top500:site[count(. | key('sites-by-country', top500:country)[1]) = 1]">
		                <xsl:sort select="top500:country"/>

                  <tr>
                     <td>
                        <xsl:value-of select="top500:country"/>
                     </td>
                     <td>
                        <xsl:value-of select="count(key('sites-by-country', top500:country))"/>
                     </td>
                     <td>
                     	  <xsl:value-of select="round(count(key('sites-by-country', top500:country)) div 500 * 100 * 100) div 100"/>
                     	  <xsl:text>%</xsl:text>
                     	</td>
                  </tr>
		
	              </xsl:for-each>
__________________
/- Sam Judson : Wrox Technical Editor -/

Think before you post: What have you tried?





Similar Threads
Thread Thread Starter Forum Replies Last Post
XSLT output path route chameleon XSLT 3 October 3rd, 2009 11:09 AM
XSLT Variable output mrame XSLT 2 March 26th, 2009 06:51 AM
XSLT to get hyperlinks in output ashv XSLT 2 December 7th, 2008 06:14 AM
XSLT output with tags trinkets XSLT 22 November 14th, 2006 11:22 AM
XSLT Looks right, but no output Alderian72 XSLT 1 June 9th, 2005 08:47 AM





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