[XSL-LIST Mailing List Archive Home]
[By Thread]
[By Date]
At 2008-05-12 17:37 -0700, Jack Bates wrote:
And the analogue in XPath: the lang() function
I disagree. That is too literal for xml:lang because if there was a property with xml:lang="fr-ca" (Canadian French) and not one with xml:lang="fr" (French), then you would inappropriately assume there is no French available.
There is also the issue of case ... lang() correctly supports a caseless match while your proposal does not.
There is also the issue of ancestry ... an ancestor of the element will in fact specify the language of the element when the element doesn't have an xml:lang= attribute.
But ... I haven't typically seen lang() used in a predicate and I can see an issue.
The XPath expression "title[lang('fr')]" (you don't need the leading "./") would return more than one title if the children of the context element included:
... but that XPath expression does return the set of matching titles without having to do an iteration.
There is no way to weigh either of these as "closer" to 'fr' than the other when you use the lang() function. So you will have to decide what to do when more than one item is returned for a given language. If you know your data set won't have such ambiguity, then there won't be a problem using lang() as I suggest.
"title[lang($preferredLanguage)]"
Sorry ... no suggestions ... I'm focused on the XPath and how I teach the XSLT. I'll let others comment on the API.
I hope this helps.
. . . . . . . . . . . . Ken
Re: [xsl] element in most preferred language expression?
Subject: Re: [xsl] element in most preferred language expression? From: "G. Ken Holman" <gkholman@xxxxxxxxxxxxxxxxxxxx> Date: Mon, 12 May 2008 21:29:10 -0400 |
At 2008-05-12 17:37 -0700, Jack Bates wrote:
For the most part, everything we could want from our API can be expressed in XPath. One challenge I am facing is multilingual data.
Many of our object's properties may be translated into foreign languages. Happily, I think there is an analogue in XML: the xml:lang attribute.
And the analogue in XPath: the lang() function
The HTTP Accept-Language request header contains a list of the user's language preferences and associated weights.
Our API can express the value of a property in a given language. I think the corresponding XPath expression would be something like: ./title[@xml:lang = "fr"]
I disagree. That is too literal for xml:lang because if there was a property with xml:lang="fr-ca" (Canadian French) and not one with xml:lang="fr" (French), then you would inappropriately assume there is no French available.
There is also the issue of case ... lang() correctly supports a caseless match while your proposal does not.
There is also the issue of ancestry ... an ancestor of the element will in fact specify the language of the element when the element doesn't have an xml:lang= attribute.
But ... I haven't typically seen lang() used in a predicate and I can see an issue.
The XPath expression "title[lang('fr')]" (you don't need the leading "./") would return more than one title if the children of the context element included:
<title xml:lang="FR">Bonjour!</title> <title xml:lang="fr-ca">Salut!</title>
... but that XPath expression does return the set of matching titles without having to do an iteration.
There is no way to weigh either of these as "closer" to 'fr' than the other when you use the lang() function. So you will have to decide what to do when more than one item is returned for a given language. If you know your data set won't have such ambiguity, then there won't be a problem using lang() as I suggest.
- the challenge is expressing the value of a property in the most preferred language. I can do this in code, by iterating over the user's language preferences, getting the property value in each language until I get a non-empty node set. However I would like to capture this behaviour behind our API. Ideally a developer could express the value of a property in the user's most preferred language in a single expression. Furthermore, this expression could be combined with other expressions, to get for example, the titles of all an object's children, in the user's most preferred language.
What is the closest XPath expression which could get the value of an element in a most preferred language?
"title[lang($preferredLanguage)]"
What advice do you have for how to express this in our API?
Sorry ... no suggestions ... I'm focused on the XPath and how I teach the XSLT. I'll let others comment on the API.
I hope this helps.
. . . . . . . . . . . . Ken
-- World-wide corporate, govt. & user group XML, XSL and UBL training RSS feeds: publicly-available developer resources and training G. Ken Holman mailto:gkholman@xxxxxxxxxxxxxxxxxxxx Crane Softwrights Ltd. http://www.CraneSoftwrights.com/s/ Box 266, Kars, Ontario CANADA K0A-2E0 +1(613)489-0999 (F:-0995) Male Cancer Awareness Nov'07 http://www.CraneSoftwrights.com/s/bc Legal business disclaimers: http://www.CraneSoftwrights.com/legal
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
[xsl] element in most preferred lan, Jack Bates | Thread | Re: [xsl] element in most preferred, Wendell Piez |
[xsl] element in most preferred lan, Jack Bates | Date | Re: [xsl] Page break help, G. Ken Holman |
Month |