XPATH Basic question

Discussion in 'XML' started by bjam, Apr 28, 2005.

  1. bjam

    bjam Guest

    Hi, a quick basic question here on XPATH

    if I have the following data

    <X>
    <X1>TEST</X1>
    <Z>
    <Z1>Item 1</Z1>
    <Z2>Item 2</Z2>
    <Z3>Item 3</Z3>
    </Z>
    </X>
    <X>
    <X1>TEST2</X1>
    <Z>
    <Z1> ... </Z1>
    <Z2> ... etc.
    </Z>
    </X>

    will the following XPATH statement be valid in a template match
    statement? My experience has been no, and I have had to get the root
    node X and then do an if on X1 before processing. See below for the
    statement. Any ideas on how to get this to work in a single XPATH
    statement?


    <xsl:template match="/X/X1[starts-with(text(),'TEST2']/Z">
    <!-- assumption here is that I get the <Z> node to process -->
    <!-- however I am thinking that the predicate has to be the last
    statement in an XPATH statement, is this true?-->
    bjam, Apr 28, 2005
    #1
    1. Advertising

  2. "bjam" <> wrote in message
    news:...
    > Hi, a quick basic question here on XPATH
    >
    > if I have the following data
    >
    > <X>
    > <X1>TEST</X1>
    > <Z>
    > <Z1>Item 1</Z1>
    > <Z2>Item 2</Z2>
    > <Z3>Item 3</Z3>
    > </Z>
    > </X>
    > <X>
    > <X1>TEST2</X1>
    > <Z>
    > <Z1> ... </Z1>
    > <Z2> ... etc.
    > </Z>
    > </X>
    >
    > will the following XPATH statement be valid in a template match
    > statement? My experience has been no, and I have had to get the root
    > node X and then do an if on X1 before processing. See below for the
    > statement. Any ideas on how to get this to work in a single XPATH
    > statement?
    >
    >
    > <xsl:template match="/X/X1[starts-with(text(),'TEST2']/Z">


    Yes.

    > <!-- assumption here is that I get the <Z> node to process -->
    > <!-- however I am thinking that the predicate has to be the last
    > statement in an XPATH statement, is this true?-->


    No.


    Cheers,
    Dimitre Novatchev
    Dimitre Novatchev, Apr 28, 2005
    #2
    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,957
    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. Tjerk Wolterink

    XPath: efficiency in xpath expressions

    Tjerk Wolterink, Nov 13, 2004, in forum: XML
    Replies:
    1
    Views:
    1,612
    Richard Tobin
    Nov 13, 2004
Loading...

Share This Page