[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: Re: XPath to select node according to xml:lang at

Subject: Re: Re: XPath to select node according to xml:lang attribute
From: Philipp Kursawe <phil.kursawe@xxxxxxxxx>
Date: Sat, 16 Apr 2011 20:37:36 +0200
Re:  Re: XPath to select node according to xml:lang  at
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.

On Sat, Apr 16, 2011 at 12:37 AM, Wendell Piez <wapiez@xxxxxxxxxxxxxxxx>
> Hi,
> On 4/15/2011 2:22 PM, Chris wrote:
>> Hash: SHA1
>> On 04/15/2011 02:18 PM, Philipp Kursawe wrote:
>>> Hmm I cannot use XSLT in my context. I can only use XPath. So I guess
>>> I would have to select "en-us" first and see if there is a result, if
>>> not select "en" and so on. Or could I "||" chain multiple XPath
>>> selects?
>>> //text[@id='color' and lang('en-us')] || //text[@id='color' and
>>> lang('en')] || //text[@id='color']
>> Not sure what your context is... B You canbt put the || in an XPath, but
>> if youbre in some procedural language like Perl or Java, then yes.
>> Pseudocode:
>> color_label = select( "//text[@id='color' and lang('en-us')]" ) ||
>> B  B  B  B  B  B  B  select( "//text[@id='color' and lang('en')]" ) ||
>> B  B  B  B  B  B  B  select( "//text[@id='color']" )
>> That would (presuming normal behavior of logical or) get the best match
>> for you.
> 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'][
> B @xml:lang='en-us' or
> B (@xml:lang='en' and not(../@xml:lang='en-us') or
> B 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]
> Cheers,
> Wendell
> ======================================================================
> Wendell Piez B  B  B  B  B  B  B  B  B  B  B  B  B 
B mailto:wapiez@xxxxxxxxxxxxxxxx
> Mulberry Technologies, Inc. B  B  B  B  B  B  B 
B http://www.mulberrytech.com
> 17 West Jefferson Street B  B  B  B  B  B  B  B  B  B Direct Phone:
> Suite 207 B  B  B  B  B  B  B  B  B  B  B  B  B  B  B  B  B  B  B  B 
B Phone: 301/315-9631
> Rockville, MD B 20850 B  B  B  B  B  B  B  B  B  B  B  B  B  B  B  B  Fax:
> ----------------------------------------------------------------------
> B Mulberry Technologies: A Consultancy Specializing in SGML and XML
> ======================================================================

Current Thread


Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
First Name
Last Name
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.