Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > XML > simple XPath query

Reply
Thread Tools

simple XPath query

 
 
R
Guest
Posts: n/a
 
      02-18-2005
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
 
Reply With Quote
 
 
 
 
Joris Gillis
Guest
Posts: n/a
 
      02-19-2005
Tempore 23:15:41, die Friday 18 February 2005 AD, hinc in foro {comp.text.xml} scripsit R <(E-Mail Removed)>:

> <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-v...i?userid=38041)
Veni, vidi, wiki (http://www.wikipedia.org)
 
Reply With Quote
 
 
 
 
David Carlisle
Guest
Posts: n/a
 
      02-19-2005

> <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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
"Memory leak" in javax.xml.xpath.XPath Marvin_123456 Java 4 07-29-2005 03:49 PM
xpath query query David Gordon XML 2 05-18-2005 03:33 PM
NEWBIE: Very simple XPATH query Victor XML 1 02-18-2004 12:25 PM
Simple XPath query raheel ASP .Net 0 11-04-2003 04:57 PM
Problem selecting a node with XPATH if attribute value contains backslashes - how to force XPATH string to be treated as literal? Alastair Cameron XML 1 07-08-2003 07:24 PM



Advertisments