simple XPath query

Discussion in 'XML' started by R, Feb 18, 2005.

  1. R

    R Guest

    Hello everybody.

    I'm new to XML and I've got problem with one XPath query.
    This is my situation:
    <group>
    <test required='1'></test>
    <test required='1' noregexp='1'></test>
    </group>

    inside group there are few (usually from 10 to 20) test nodes.

    if among all of the tests there is at least one node that doesn't have
    "noregexp" attribute - like in the above example
    I should call template for validating regexps.

    well my idea was this:

    if (count(required) != count(required and noregexp) ) { call template }

    if counts varies that means there is a node that need to be validated
    (at least one node)

    in XPath:

    <xsl:if test="count(*/@required='1' and */@noregexp='1') != count(*/@required='1')">
    <!-- my template goes here -->
    </xsl:if>

    but this XPath query is incorrect and I don't know how to fix it

    sorry for bothering but I'm just a newbie

    thanks in advance for helping me with this query

    best regards R
     
    R, Feb 18, 2005
    #1
    1. Advertising

  2. R

    Joris Gillis Guest

    Tempore 23:15:41, die Friday 18 February 2005 AD, hinc in foro {comp.text.xml} scripsit R <>:

    > <xsl:if test="count(*/@required='1' and */@noregexp='1') != count(*/@required='1')">
    > <!-- my template goes here -->
    > </xsl:if>
    >
    > but this XPath query is incorrect and I don't know how to fix it
    >

    Hi,

    You're forgetting that predicates should be between [brackets]

    <xsl:if test="count(*[@required='1' and @noregexp='1']) != count(*[@required='1'])">

    Be careful with '!= ' , you'de better use 'not(...=...)'


    regards,
    --
    Joris Gillis (http://www.ticalc.org/cgi-bin/acct-view.cgi?userid=38041)
    Veni, vidi, wiki (http://www.wikipedia.org)
     
    Joris Gillis, Feb 19, 2005
    #2
    1. Advertising


  3. > <group>
    > <test required='1'></test>
    > <test required='1' noregexp='1'></test>
    > </group>
    >
    > inside group there are few (usually from 10 to 20) test nodes.
    >
    > if among all of the tests there is at least one node that doesn't have
    > "noregexp" attribute - like in the above example
    > I should call template for validating regexps.
    >
    > well my idea was this:
    >
    > if (count(required) != count(required and noregexp) ) { call template }
    >


    that's more complicated (for you and the system) than necessary.
    There is no need to count anything: The Xpath can more closely model
    your description in English:

    test="test[not(@noregexp)]"

    matches the description

    > if among all of the tests there is at least one node that doesn't have
    > "noregexp" attribute -


    although your attempt seems to be implementing:

    if among all of the tests __that have a required attribute__ there is at
    least one node that doesn't have "noregexp" attribute -

    which would be


    test="test[@required and not(@noregexp)]"

    David
     
    David Carlisle, Feb 19, 2005
    #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. raheel

    Simple XPath query

    raheel, Nov 4, 2003, in forum: ASP .Net
    Replies:
    0
    Views:
    358
    raheel
    Nov 4, 2003
  2. Marvin_123456

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

    Marvin_123456, Jul 29, 2005, in forum: Java
    Replies:
    4
    Views:
    1,993
    jan V
    Jul 29, 2005
  3. Alastair Cameron
    Replies:
    1
    Views:
    7,443
    SQL Server Development Team [MSFT]
    Jul 8, 2003
  4. Victor
    Replies:
    1
    Views:
    356
    Philippe Poulard
    Feb 18, 2004
  5. David Gordon

    xpath query query

    David Gordon, May 18, 2005, in forum: XML
    Replies:
    2
    Views:
    805
    David Gordon
    May 18, 2005
Loading...

Share This Page