Skip to main content
1-Visitor
March 26, 2014
Question

XPATH help

  • March 26, 2014
  • 7 replies
  • 1871 views

<
<listitem><para>text
<randomlist>
<I am here<para>text</para></listitem>
<listitem><para>text</para></listitem>
<listitem><para>text</para></listitem>
</randomlist>
</para></listitem>
</randomlist>

I'm trying to test if the top randomList has listItemPrefix="pf01" and ignore it if it doesn't have the attribute set


This doesn't work, I thought it would take me to the first randomList ancestor of listitem parent
../ancestor::randomList[1][@listitemPrefix='pf01']


Thanks for any help!

    7 replies

    12-Amethyst
    March 26, 2014
    Try: ../randomList/@listItemPrefix="pf01"


    Trevor Hendricks<">mailto:->
    Project Analyst -- Publication Systems
    Technical Communications, MS: 078
    cleccese1-VisitorAuthor
    1-Visitor
    March 26, 2014

    Thank you, Trevor, that didn't work.

    10-Marble
    March 26, 2014
    Hi Caroline,

    Maybe ancestor::randomList[last()][@listitemPrefix='pf01']
    The ancestors are listed in reverse order, so you want the
    last one to get the outer one.

    Regards,
    Richard

    cleccese1-VisitorAuthor
    1-Visitor
    March 26, 2014

    this works:


    ../ancestor::randomList[1][@listItemPrefix='pf01']


    Wait, what? That's what I had originally, but now it's working for some reason.

    cleccese1-VisitorAuthor
    1-Visitor
    March 26, 2014

    Thanks, Richard, unfortunately didn't work. (There were two randomLists, easy to miss)

    1-Visitor
    March 26, 2014
    How about:

    ./ancestor::randomlist[@listItemPrefix="pf01" and not(ancestor::randomlist)]

    So that would be looking for an ancestor that has the prefix, but also is
    not a child of other randomlists?


    On Wed, Mar 26, 2014 at 11:43 AM, Hendricks Trevor <
    -> wrote:

    > Try: ../randomList/@listItemPrefix="pf01"
    >
    >
    >
    >
    >
    > *Trevor Hendricks* <->
    > Project Analyst -- Publication Systems
    > Technical Communications, MS: 078
    >
    > *m*: 920-226-2116
    > *p*: 920-457-4441; ext. 73571
    > *f*: 920-803-3939
    > *e*: -
    > *Experience gracious living with **Kohler
    >
    >
    >
    > Math problems?? Call 1-800-10x(24+13)-(64-8y)/2+36x-17.
    >
    >
    >
    >
    >
    >
    >
    > *From:* Caroline Leccese [
    > <listitem><para>text
    > <randomlist>
    > <listitem>I am here<para>text</para></listitem>
    > <listitem><para>text</para></listitem>
    > <listitem><para>text</para></listitem>
    > </randomlist>
    > </para></listitem>
    > </randomlist>
    >
    > I'm trying to test if the top randomList has listItemPrefix="pf01" and
    > ignore it if it doesn't have the attribute set
    >
    > This doesn't work, I thought it would take me to the first randomList
    > ancestor of listitem parent
    > ../ancestor::randomList[1][@listitemPrefix='pf01']
    >
    > Thanks for any help!
    >
    >
    cleccese1-VisitorAuthor
    1-Visitor
    March 26, 2014

    Hi Keith,


    Thanks for the reply, unfortunately it didn't work.


    This did: ../ancestor::randomList[1][@listItemPrefix='pf01']