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 March 23rd, 2004, 12:05 PM
lxxxi lxxxi is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2004
Posts: 2 lxxxi User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
XSL selective alphabetical sort

Hi,

I am currently trying to alphabetically sort an xml file containing a list of movies. This proved pretty simple using the following:

<xsl:for-each select="collection/movie">
<xsl:sort select="title" />
.......
</xsl:for-each>

However, all the movies beginning with the word "The" are obviously listed together in the "T" section. I would like the sort to ignore articles at the start of the title. Does anyone know how to do this?

Thanks

Reply With Quote
  #2  
Old March 23rd, 2004, 04:08 PM
MattSidesinger's Avatar
MattSidesinger MattSidesinger is offline
Java PHP Oracle Developer
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2004
Location: C-Bus OH-IO
Posts: 204 MattSidesinger User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 15 m 26 sec
Reputation Power: 5
Send a message via AIM to MattSidesinger
There is no immediate solution within the current XSL transformation because we are using an xsl:sort.

This is what you have now:
XML_1 -> XSL_Transformation_1 -> output

This is what you should do:
XML_1 -> XSL_Transformation_2 -> XML_2 - > XSL_Transformation_1 -> output

XSL_Transformation_2 takes all of the titles in XML_1 that begin with "The", remove the "The", and add ", The" to the end of the current title. This would then be added to the parent element with an element called sortTitle. titles that don't start with the would just be copied to the sortTitle element. This way you would keep the original title element for display purposes. Then just do the xsl:sort on sortTitle.

If you need help writing the template for XSL_Transformation_2 let me know and I can help.

Reply With Quote
  #3  
Old March 23rd, 2004, 07:08 PM
lxxxi lxxxi is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2004
Posts: 2 lxxxi User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
That sounds like it does something like what I want; however, I confess to being fairly new to xsl! Could you give me something of an example?

Thanks again

Reply With Quote
  #4  
Old March 24th, 2004, 06:15 AM
teedee teedee is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2003
Posts: 42 teedee User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 6
This is not a perfect solution as it ignores any occurence of "The " in the XML - you could possibly improve it using substring() somewhere in the xsl:sort ...
Code:
				<xsl:for-each select="/collection/movie">
					<xsl:sort select="translate(title, 'The ', '')"/>
					<xsl:value-of select="title"/>
					<br/>
				</xsl:for-each>

Reply With Quote
  #5  
Old March 24th, 2004, 08:29 AM
MattSidesinger's Avatar
MattSidesinger MattSidesinger is offline
Java PHP Oracle Developer
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2004
Location: C-Bus OH-IO
Posts: 204 MattSidesinger User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 15 m 26 sec
Reputation Power: 5
Send a message via AIM to MattSidesinger
Teedee-

Your solution is no good. You don't have a good understanding of the translate function. I believe that you are under the impression that translate will replace all occurences of the word "The " with "", but it does not. What happens instead is that all 'T', 'h', 'e', and ' ' characters are replaces with ''.

I am sticking to my original answer.

Last edited by MattSidesinger : March 24th, 2004 at 04:49 PM. Reason: Change in answer - see bold text.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreXML Programming > XSL selective alphabetical sort


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 | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway
Stay green...Green IT