xsl-list
[Top] [All Lists]

Re: [xsl] Re: XPath to select node according to xml:lang attribute

2011-04-18 10:18:23
Philipp,

On 4/16/2011 2:37 PM, Philipp Kursawe wrote:
Thanks Wendell, I will try that! I think I have to go with the 1.0
version since Windows CE MSXML parser can only handle 1.0 expressions.

Sure. But if it were my code I wouldn't be traversing to //text each time, but operating from some local context (probably the parent element of the set of text siblings I am interested in).

If that doesn't make sense to you, maybe it's time to review some of the literature on basic XPath. :-)

Cheers,
Wendell

Keep in mind, however, that what we have in XPath 1.0 "|" is a union
operation, not an "or". So,

//text[@id='color' and lang('en-us')] |
//text[@id='color' and lang('en')] |
//text[@id='color']

will get us all the nodes in //text that have @id='color', irrespective of
their lang() value, because the third term in the union collects them.

To do a cascading conditional like this in XPath 1.0 alone generally
requires building conditionals into the predicates, as in

//text[@id='color'][
  @xml:lang='en-us' or
  (@xml:lang='en' and not(../@xml:lang='en-us') or
  not(../@xml:lang='en-us' or../@xml:lang='en')] ]

where the fallback cases (the second and third operands of the boolean 'or'
here) are excluded by filtering themselves out when the preferred cases are
available.

Here the attribute values are tested directly since the lang() function
works only on the context node, and we have to test the siblings. (So we
have to do without the case-insensitive test built into lang().)

This is easier in XPath 2.0, where we can do something like

//text[@id='color]/(.[lang('en-us')],.[lang('en')],.)[1]

--
======================================================================
Wendell Piez                            
mailto:wapiez(_at_)mulberrytech(_dot_)com
Mulberry Technologies, Inc.                http://www.mulberrytech.com
17 West Jefferson Street                    Direct Phone: 301/315-9635
Suite 207                                          Phone: 301/315-9631
Rockville, MD  20850                                 Fax: 301/315-8285
----------------------------------------------------------------------
  Mulberry Technologies: A Consultancy Specializing in SGML and XML
======================================================================

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--