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

Re: How to select an attribute on the current node or

Subject: Re: How to select an attribute on the current node or its anchestor
From: Brandon Ibach <brandon.ibach@xxxxxxxxxxxxxxxxxxx>
Date: Fri, 15 Apr 2011 14:47:14 -0400
Re:  How to select an attribute on the current node or
You need to be careful not to get tripped up by the text nodes in your
document that consist of nothing but whitespace.  Try:

ancestor-or-self::*/text()[normalize-space(.) != ''][last()]

-Brandon :)


On Fri, Apr 15, 2011 at 12:29 PM, Philipp Kursawe
<phil.kursawe@xxxxxxxxx> wrote:
> and I guess to fetch the text() of the current node or its ancestor I
> would have to use:
> ancestor-or-self::*[text/text()][1]/text()
>
> This however does return an empty node for this xml:
> <phrase id="goodbye">
>    <text xml:lang="en">See you tomorrow!</text>
>
>    <text weight="dayOfWeek"
>          days="fri">
>      <text xml:lang="en">Have a nice weekend!</text>
>      <text id="weekend_summer"
>            weight="month"
>            months="4,5,6,7,8,9,10">
>        <text alt="garden" icon="data:binary;..."/>
>        <text alt="boat" icon="data:binary;..."/>
>      </text>
>    </text>
>  </phrase>
>
> and
>
> ancestor-or-self::*[text/text()][1]/text does return the text node.
> But I would like to select the text() in one select.
>
> I tried
> //*[@id='weekend_summer']/ancestor-or-self::*[text/text()][1]/text
> which returns
> <text xml:lang="en">Have a nice weekend!</text>
>
> But i would like to fetch the text() node directly.
>
> Thanks all for your help!
> Phil
> On Fri, Apr 15, 2011 at 8:33 AM, Brandon Ibach
> <brandon.ibach@xxxxxxxxxxxxxxxxxxx> wrote:
>> ancestor-or-self::*[@data][1]/@data
>>
>> -Brandon :)
>>
>>
>> On Fri, Apr 15, 2011 at 2:06 AM, Philipp Kursawe <phil.kursawe@xxxxxxxxx>
wrote:
>>> Hello,
>>>
>>> given the following xml:
>>>
>>> <node data="foo">
>>>   <text id="1" data="bar"/>
>>>   <text id="2"/>
>>> </node>
>>>
>>> I would like to know the XPath expression to select @data which
>>> results in "bar" for @id=1 and "foo" for @id=2.
>>>
>>> The general idea is to search for the attribute in the anchestor if
>>> the current node does not contain the attribute all the way up to the
>>> root node.
>>>
>>> Thanks for your help!
>>>
>>> Phil

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

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.
Email
First Name
Last Name
Company
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.