simple XPath query

R

R

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
 
J

Joris Gillis

Tempore 23:15:41 said:
<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,
 
D

David Carlisle

<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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,535
Members
45,008
Latest member
obedient dusk

Latest Threads

Top