473,497 Members | 2,093 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

alphabetical ordering into groups?

I have the following xml data and would like to format it the following
way with xslt:

1. I need to sort them after there last name (see my example below)
2. I only want to display the main header character (fx. M) if there
are any last names that starts with fx. M
3. I allso need to color every second line under each character
Group..but this is proppery easy so focus on the thing abowe :)

XML data:
------------------
<root>
<Worker>
<Firstname>Andrew</Firstname>
<Lastname>Pitt</Lastname>
</Worker>
<Worker>
<Firstname>Peter</Firstname>
<Lastname>Michael</Lastname>
</Worker>
<Worker>
<Firstname>John</Firstname>
<Lastname>Allisi</Lastname>
</Worker>
<Worker>
<Firstname>Michael</Firstname>
<Lastname>More</Lastname>
</Worker>
</root>

-----------------
The output should look something like this:
---------------

A - M - P
A
John Allisi

M
Michael More
Peter Michael

P
Andrew Pitt

----------------

Oct 22 '05 #1
4 1339
pr**********@gmail.com wrote:
I have the following xml data and would like to format it the following
way with xslt:

1. I need to sort them after there last name (see my example below)
xsl-sort
2. I only want to display the main header character (fx. M) if there
are any last names that starts with fx. M
XSL FAQ: http://www.dpawson.co.uk/xsl/xslfaq.html, look under
"Muenchian Grouping"
3. I allso need to color every second line under each character
Group..but this is proppery easy so focus on the thing abowe :)


http://www.dpawson.co.uk/xsl/sect2/N7450.html#d9829e82 explains this
for tables. It shouldn't be hard to adapt for your sections.

///Peter
--
XML FAQ: http://xml.silmaril.ie/

Oct 22 '05 #2
Thanks, but i still have some problems......i am very new to XSLT.

I am trying to use the folloing xslt, but the output isnt right.
"Kalene Bilco" and "Katrine Bower" should both be under "header B".
-------------------------------
Header :A
John Alias
Header :B
Katrine Bower
Header :B
Kalene Bilco
Header :C
Conny Carlzon

------------------------------

My xslt:
--------------------------------

<xsl:key name="contacts-by-surname" match="Worker" use="Lastname" />
<xsl:template match="root">
<xsl:for-each select="Worker[count(. | key('contacts-by-surname',
Lastname)[1]) = 1]">
<xsl:sort select="Lastname" />
<strong>Header :<xsl:value-of select="substring(Lastname, 1,1 )"
/></strong><br />
<xsl:for-each select="key('contacts-by-surname', Lastname)">
<xsl:sort select="Firstname" />
<xsl:value-of select="Firstname" /> <xsl:value-of
select="Lastname" /><br />
</xsl:for-each>
</xsl:for-each>
</xsl:template>
------------------------

Oct 23 '05 #3
Me again :)

im allmost there but my output looks like this now......The problem is
that the B section i in there x2....i need help to remove one of the
sections so i dont have any duplicates.
--------------
A
Jay Arla
B
Katrine Bower
Kane Bingo
B
Katrine Bower
Kane Bingo
C
Kanye Carlson

---------------
XSLT
---------------
<xsl:key name="contacts-by-surname" match="Worker"
use="substring(Lastname, 1, 1)" />
<xsl:template match="root">
<xsl:for-each select="Worker[not(surname =
preceding-sibling::Worker/Lastname)]">
<xsl:sort select="Lastname" />
<strong><xsl:value-of select="substring(Lastname, 1, 1)"
/></strong><br />
<xsl:for-each select="key('contacts-by-surname', substring(Lastname,
1, 1))">
<xsl:sort select="Lastname" />
<div>
<xsl:if test="position() mod 2 != 0">
<xsl:attribute
name="style">background-color:#cccccc;width:200px;</xsl:attribute>
</xsl:if>
<xsl:value-of select="Firstname" /> <xsl:value-of
select="Lastname" /><br />
</div>
</xsl:for-each>
</xsl:for-each>

----------'

Oct 23 '05 #4
Mokka wrote:
Me again :)

im allmost there but my output looks like this now......The problem is
that the B section i in there x2....i need help to remove one of the
sections so i dont have any duplicates.


You were close the first time. I think this is what you want:

<?xml version="1.0" encoding="iso-8859-1"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">

<xsl:output method="html"/>
<xsl:strip-space elements="*"/>

<xsl:key name="contacts-by-surname" match="Worker"
use="substring(Lastname,1,1)"/>

<xsl:template match="root">
<p>
<xsl:for-each
select="Worker[count(.|
key('contacts-by-surname',substring(Lastname,1,1))[1])=1]">
<xsl:sort select="Lastname"/>
<a>
<xsl:attribute name="href">
<xsl:text>#</xsl:text>
<xsl:value-of select="substring(Lastname,1,1)"/>
</xsl:attribute>
<xsl:value-of select="substring(Lastname,1,1)"/>
</a>
<xsl:if test="position()!=last()">
<xsl:text>&#x00A0;-&#x00A0;</xsl:text>
</xsl:if>
</xsl:for-each>
</p>
<xsl:for-each
select="Worker[count(.|
key('contacts-by-surname',substring(Lastname,1,1))[1])=1]">
<xsl:sort select="Lastname"/>
<p>
<b>
<a>
<xsl:attribute name="name">
<xsl:value-of select="substring(Lastname,1,1)"/>
</xsl:attribute>
<xsl:value-of select="substring(Lastname,1,1)"/>
</a>
</b>
<xsl:for-each
select="key('contacts-by-surname',substring(Lastname,1,1))">
<xsl:sort select="Lastname"/>
<xsl:sort select="Firstname"/>
<br/>
<xsl:value-of select="Firstname"/>
<xsl:text>&#x00A0;</xsl:text>
<xsl:value-of select="Lastname"/>
</xsl:for-each>
</p>
</xsl:for-each>
</xsl:template>

</xsl:stylesheet>

///Peter
--
XML FAQ: http://xml.silmaril.ie/

Oct 23 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
2050
by: R.G. Vervoort | last post by:
Does anyone have a suggestion how I can order a list with names in a secondary select string. The first string selects a number of locations where people work From this string I get...
1
1461
by: Rim | last post by:
Hi, Is there a way to get any sort of introspection which would return the content of an instance *in the order they were declared or executed* as opposed to alphabetical order? Example: ...
2
587
by: Ken Fine | last post by:
(originally posted to one of macromedia's groups; no help, so hopefully someone here can help me out. I'm using VBScript ASP.) When designing administrative interfaces to websites, we often need...
15
1723
by: Kay Schluehr | last post by:
Here might be an interesting puzzle for people who like sorting algorithms ( and no I'm not a student anymore and the problem is not a students 'homework' but a particular question associated with...
2
1270
by: Marco Castro | last post by:
I want the users to be able to reorder the columns in a few of my listview controls. It's easy enough to make that change in the listview control but I can't seem to find a way to get the new...
5
1229
by: Joe Molloy | last post by:
Hi Group, I have a task and I'm interested to see what ideas people have here for the best way of tackling it. I have a table of products. Each of the products is associated with a certain...
10
1454
by: bill | last post by:
I have a database of kennels. One page lists the kennels alphabetically by kennel name. I have a field for kennel name and an index with kennel name as the only field. Some of the kennels have...
2
4342
by: bassrider | last post by:
Hi There, I am trying to order my months in calendar format (Jan, Feb, Mar...), but I can not. It only shows in alphabetical order (Apr,Aug,Dec..). Does anyone now how I can change the order from...
6
1518
by: Jeff | last post by:
Lets say we have an array: $array='apples'; $array='orange'; $array='lemon'; echo $array; // orange Now, lets say we want to insert "grape", between apples and orange. How
0
7120
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
6991
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7160
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7196
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
5456
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4897
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4583
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
1405
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
286
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.