Go Back   Velocity Reviews > Newsgroups > XML
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

Reply

XML - XSLT: path expression

 
Thread Tools Search this Thread
Old 05-13-2006, 11:45 PM   #1
Default XSLT: path expression


Hi,

I would like to initialize a variable
but need help selecting the appropriate node.

How can I select

the only anchor element of a
section element,(anywhere in the document), whose only
section_header element's text is equal to "Menus"?

<chapter>
<section/>
<section/>
<section>
<anchor>3_Menus</anchor>
<section_header>Menus</section_header>
</section>
<section/>
</chapter>

Variable value would equal "3_Menus".

I've tried several expressions including,
//section/anchor[parent::section_header/text() =" Menus"],
but no luck so far.

Thanks
Jeff Higgins




Jeff Higgins
  Reply With Quote
Old 05-13-2006, 11:54 PM   #2
Joe Kesselman
 
Posts: n/a
Default Re: XSLT: path expression

> //section/anchor[parent::section_header/text() =" Menus"],

1) parent:: specifies an axis, not a step. Not what you're looking for.

2) If you want to test the entire text content of an element, you can do
so directly. Explicitly using text() means you're looking for a single
text node whose value matches the one you've specified. Doesn't make a
difference in this case either way, but worth pointing out for future.

3) If you want to match "Menus", don't write " Menus" ... (I presume
that was just a typo.

Summary: Try either
section/anchor[../section_header="Menus"]
or
section/anchor[../section_header/text()="Menus"]

(I'd use the former.)

--
() ASCII Ribbon Campaign | Joe Kesselman
/\ Stamp out HTML e-mail! | System architexture and kinetic poetry
  Reply With Quote
Old 05-14-2006, 12:19 AM   #3
Jeff Higgins
 
Posts: n/a
Default Re: XSLT: path expression


Joe Kesselman wrote:

>> //section/anchor[parent::section_header/text() =" Menus"],

>
> 1) parent:: specifies an axis, not a step. Not what you're looking for.


axis - step - got it + more studies
>
> 2) If you want to test the entire text content of an element, you can do
> so directly. Explicitly using text() means you're looking for a single
> text node whose value matches the one you've specified. Doesn't make a
> difference in this case either way, but worth pointing out for future.


<A>This is some <b>BOLD</b>text.</A> - A/text()[2] = "text." ? I'll check it
out.
>
> 3) If you want to match "Menus", don't write " Menus" ... (I presume that
> was just a typo.


Yes, in my stylesheet8-P
>
> Summary: Try either
> section/anchor[../section_header="Menus"]
> or
> section/anchor[../section_header/text()="Menus"]
>
> (I'd use the former.)
>


Thanks Joe. Appreciate it.
Jeff Higgins


  Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump