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 .
