XPATH help with Expression

Discussion in 'XML' started by Jerry O, Jun 27, 2003.

  1. Jerry O

    Jerry O Guest

    Hi -

    I am stuck on what might be a simple Xpath expression, I just can't
    visualize the query.

    I have a node set that can be the child of any of three nodes. I would
    like to test if a node matching [@url = $this-page] has the child
    <related_info type="x" />.

    Here's my XML
    <?xml?>
    <root>
    <silo>
    <level_one url="w123">
    <related_info type="x"/>
    </level_one>
    <level_two>
    <nav_item url="w234">
    <related_info type="x"/>
    </nav_item>
    <nav_item url="x234">
    <related_info type="x"/>
    </nav_item>
    </level_two>
    <level_three>
    <nav_item url="w23w">
    <related_info type="x"/>
    </nav_item>
    <nav_item url="x2ww">
    <related_info type="x"/>
    </nav_item>
    </level_three>
    </silo>
    ....
    </root>

    I need to do two things.

    1. See if the related info section exists, so I can adjust widths and
    the like.
    2. Call a named template to operate on the related_info data.

    I'm almost at the point of creating a separate (flatter) XML for the
    related_info and be done with it.

    Let me know what you think.


    Jerry
    Jerry O, Jun 27, 2003
    #1
    1. Advertising

  2. Use:

    /*/*/*[@url = $this-page and related_info[@type=''x'] ]



    I'd recommend that you get the XPath Visualizer and play with it to learn
    XPath the fun way.
    =====
    Cheers,

    Dimitre Novatchev.
    http://fxsl.sourceforge.net/ -- the home of FXSL



    "Jerry O" <> wrote in message
    news:...
    > Hi -
    >
    > I am stuck on what might be a simple Xpath expression, I just can't
    > visualize the query.
    >
    > I have a node set that can be the child of any of three nodes. I would
    > like to test if a node matching [@url = $this-page] has the child
    > <related_info type="x" />.
    >
    > Here's my XML
    > <?xml?>
    > <root>
    > <silo>
    > <level_one url="w123">
    > <related_info type="x"/>
    > </level_one>
    > <level_two>
    > <nav_item url="w234">
    > <related_info type="x"/>
    > </nav_item>
    > <nav_item url="x234">
    > <related_info type="x"/>
    > </nav_item>
    > </level_two>
    > <level_three>
    > <nav_item url="w23w">
    > <related_info type="x"/>
    > </nav_item>
    > <nav_item url="x2ww">
    > <related_info type="x"/>
    > </nav_item>
    > </level_three>
    > </silo>
    > ...
    > </root>
    >
    > I need to do two things.
    >
    > 1. See if the related info section exists, so I can adjust widths and
    > the like.
    > 2. Call a named template to operate on the related_info data.
    >
    > I'm almost at the point of creating a separate (flatter) XML for the
    > related_info and be done with it.
    >
    > Let me know what you think.
    >
    >
    > Jerry
    Dimitre Novatchev, Jun 27, 2003
    #2
    1. Advertising

  3. Jerry O

    Jerry O Guest

    Hi Guys -

    Thanks for the help. I used Dimitre's solution; tried them both but
    managed to get his working first. Although, I like the idea of using a
    key and will experiment with that version when I have more time, for
    right now the straight XPATH was simpler.

    I agree with Marrow that I should not have mixed data into element
    names but at this time, I cannot rework the XML. Parts of it are
    already in production. The good news is the structure will never go
    below three levels. Point taken for next time.

    Thanks for the tip on XPath Visualizer. It helped me catch a couple of
    typos in the solution.

    The final version ended up as :

    //*/*/*[@url = $this-page and related_info[@type='x'] ]

    Cheers,

    Jerry O
    Jerry O, Jun 27, 2003
    #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. Marvin_123456

    "Memory leak" in javax.xml.xpath.XPath

    Marvin_123456, Jul 29, 2005, in forum: Java
    Replies:
    4
    Views:
    1,958
    jan V
    Jul 29, 2005
  2. Alastair Cameron
    Replies:
    1
    Views:
    7,369
    SQL Server Development Team [MSFT]
    Jul 8, 2003
  3. Anna
    Replies:
    0
    Views:
    507
  4. goog
    Replies:
    0
    Views:
    496
  5. GIMME
    Replies:
    3
    Views:
    11,923
    vforvikash
    Dec 29, 2008
Loading...

Share This Page