XSLT: path expression

Discussion in 'XML' started by Jeff Higgins, May 13, 2006.

  1. Jeff Higgins

    Jeff Higgins Guest

    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, May 13, 2006
    #1
    1. Advertising

  2. > //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
    Joe Kesselman, May 13, 2006
    #2
    1. Advertising

  3. Jeff Higgins

    Jeff Higgins Guest

    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
    Jeff Higgins, May 14, 2006
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Stylus Studio
    Replies:
    0
    Views:
    631
    Stylus Studio
    Aug 3, 2004
  2. Benjamin Hillsley
    Replies:
    3
    Views:
    1,655
    Dimitre Novatchev
    Sep 25, 2003
  3. ted
    Replies:
    1
    Views:
    610
    Laurens
    Jan 26, 2004
  4. Replies:
    2
    Views:
    704
    Henry S. Thompson
    Oct 19, 2005
  5. Replies:
    4
    Views:
    651
Loading...

Share This Page