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 July 1st, 2003, 11:34 PM
Registered User
 
Join Date: Jul 2003
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Difficult sorting problem

Hi there,

I'm trying to solve a problem that I'm sure many people must have come across before.

I am trying to print a message in the user's native language, based on their language preferences which are specified as part of the source XML. These are expressed in order of preference, e.g.:

<langPrefs>
  <pref>en</pref>
  <pref>fr</pref>
  <pref>sp</pref>
</langPrefs>

would mean "Choose English 1st, otherwise French, otherwise Spanish, otherwise choose the first one available".

A message to display would look like:

<Item>
  <message lang="en">Thank you</message>
  <message lang="fr">Merci</message>
  <message lang="sp">Gracias</message>
  <message lang="jp">Arigato</message>
</Item>

There's guaranteed to be at least one language available, but there's no ordering, and no guarantee that any of the message languages will match any of the languages specified in the user preferences. In short, the XSLT stylesheet knows nothing about the names or quantity of languages in the source XML doc, so hardcoding preferences or languages is not an option.

I was hoping to assign each user preference a priority based on it's position in the preferences, then sort the messages by priority in descending order (giving a priority of 0 if it doesn't exist in the user prefs) and then pick the top one. However, there seems no way to do this. I can work out priorities for each message, but then sorting is impossible. My brain is still thinking procedurally :)

Can anyone help? It's no problem to add a priority field to each of the user preferences, or specify them in a different way, but those priorities can't be placed inside the <message> tags as attributes .





Similar Threads
Thread Thread Starter Forum Replies Last Post
Sorting problem kuku SQL Server 2000 2 November 7th, 2005 03:36 PM
Sorting Problem whiterainbow BOOK: Access 2003 VBA Programmer's Reference 4 June 6th, 2005 12:59 AM
The difficult part k0023382 Access 1 October 8th, 2004 03:37 AM
Eric it's too difficult eureka BOOK: ASP.NET Website Programming Problem-Design-Solution 2 September 10th, 2004 03:01 AM
Simple and Difficult too sumit1228 SQL Language 1 February 4th, 2004 08:42 PM





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