[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

RE: grouping content

Subject: RE: grouping content
From: Gavin Myers <GavinM@xxxxxxxxx>
Date: Fri, 6 Apr 2001 12:59:47 -0500
gavin myers
Hello again,

I really appreciate all of the help you all gave me on my last question, i
hate to keep buggin you...

Here's what I've got now:

origonal question

Need to make this happen

Location A
Value 8
Value 5
Value 1
Location B
Value 2
Value 6
Value 1
Location C
Value 3
Value 1
Value 2

This was the xml:

<root>
 <Location Area="A" Value="23"/>
 <Location Area="A" Value="24"/>
 <Location Area="A" Value="45"/>
 <Location Area="A" Value="88"/>
 <Location Area="B" Value="38"/>
 <Location Area="B" Value="18"/>
 <Location Area="C" Value="241"/>
 <Location Area="C" Value="213"/>
</root>

With your guys help I was able to make this happen, this next part seems to
be a rather simple question:

To build the xml farther, it looks more like this:
<root>
<World>
	<NorthAmerica>
		<US>
			<Location Area="Minnesota" Scope="Rural"
Type="Grassland" value="200 Square Miles"/>
			<Location Area="Minnesota" Scope="Urban"
Type="Grassland" value="20 Square Miles"/>
			<Location Area="Minnesota" Scope="Rural"
Type="Marshland" value="100 Square Miles"/>
			<Location Area="Minnesota" Scope="Urban"
Type="Marshland" value="4 Square Miles"/>
			<Location Area="Wisconsin" Scope="Rural"
Type="Grassland" value="120 Square Miles"/>
			<Location Area="Wisconsin" Scope="Urban"
Type="Grassland" value="75 Square Miles"/>
			<Location Area="Wisconsin" Scope="Rural"
Type="Marshland" value="12 Square Miles"/>
			<Location Area="Wisconsin" Scope="Urban"
Type="Marshland" value="22 Square Miles"/>
		</US>
	</NorthAmerica>
</World>
</Root>

And the output is like this:

Minnesota

Grassland
Rural: 200 Square Miles
Urban: 20 Square Miles

Marshland
Rural: 100 Square Miles
Urban: 4 Square Miles

Wisconsin

Grassland
Rural: 120 Square Miles
Urban: 75 Square Miles

Marshland
Rural: 12 Square Miles
Urban: 22 Square Miles



Aside from the Minnesota and Wisconsin headers I had everything else
working, what I had was:

<!-- ****************************** -->
<!-- ****************************** -->
<xsl:template match="/">
<xsl:apply-templates select="//World/NorthAmerica/US">
<xsl:sort select="@Area" order="ascending"/>
<xsl:sort select="@Type" order="ascending"/>
</xsl:apply-templates>
</xsl:template>

<xsl:template match="World/NorthAmerica/US">
<!-- code -->
</xsl:template>
<!-- ****************************** -->
<!-- ****************************** -->

Even though my @value was not nestled inside a row it worked in both
netscape and ie.
I was doing this because the xml had the possibility of not being in the
exact order i wanted it.

Now when i do that, for some reason if i try:

<xsl:template match="World/NorthAmerica/US">
I cannot just have:
  <xsl:for-each select="[@Area and
generate-id(.)=generate-id(key('LocationGroups',@Area))]">

That returns an error

So I tried removing the []'s, that still returns an error. 

To make a long story short, for the code below to work I need to have it
inside the

<xsl:template match="/">

or inside a not-matched template (<xsl:template name="Data">)

Is there a way in the code below to make it run inside a matched template,
or is there a way I can order these results? (I'd paste the xml,xsl i am
working on but i'm not allowed (security risks blah blah blah)) that's why
i'm trying to get as close to my problem as possible.

<root>
 <Location Area="A" Value="23"/>
 <Location Area="A" Value="24"/>
 <Location Area="A" Value="45"/>
 <Location Area="A" Value="88"/>
 <Location Area="B" Value="38"/>
 <Location Area="B" Value="18"/>
 <Location Area="C" Value="241"/>
 <Location Area="C" Value="213"/>
</root>

<?xml version="1.0" encoding="iso-8859-1"?>
<xsl:stylesheet version="1.0" 
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
 <xsl:key name="LocationGroups" match="Location" use="@Area"/>
 <xsl:template match="/">
  <xsl:for-each select="root/Location[@Area and
generate-id(.)=generate-id(key('LocationGroups',@Area))]">
   <xsl:variable name="group" select="@Area"/>
   Location <xsl:value-of select="$group"/><br/>
   <xsl:for-each select="/root/Location[@Area=$group]">
    &#183;<xsl:value-of select="@Value"/><br/>
   </xsl:for-each>
  </xsl:for-each>
 </xsl:template>
</xsl:stylesheet>

Any info would be appreciated

Gavin

 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list




 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list




 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.