XSLT: path expression

J

Jeff Higgins

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
 
J

Joe Kesselman

//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.)
 
J

Jeff Higgins

Joe said:
//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.

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,001
Messages
2,570,254
Members
46,850
Latest member
VMRKlaus8

Latest Threads

Top