RE: XPath question

"Edvard Robertsson" <[email protected]> Sun, 18 Jan 2004 13:19:59 +0100
Newsgroups gmane.text.xml.schematron
Message-ID <[email protected]>
Hi Denny,

>I think the problem I am having is how to set up the valid cases.  I can't
>seem to create a <rule> that will match the absence of something.
>Basically, is there a way to do:
>
><rule context="PUB-ENTRY and not(BIB/NOTICE)>
>
>I want one <rule> for PUB-ENTRY that does have NOTICE (scenario 1), and
>another for PUB-ENTRY that does not have NOTICE (scenario 2).

You can do this by specifying multiple rules in one pattern with the same 
context (the PUB-ENTRY) element but with different XPath predicates. This is 
made possible by the fact that only one rule with same context can be fired 
in one pattern. So in your case you can do something like this:

<sch:pattern name="Something">
    <sch:rule context="PUB-ENTRY[BIB/NOTICE]">
        <!-- This rule will fire for all PUB-ENTRY elements with a NOTICE 
grandchild -->
    </sch:rule>
    <sch:rule context="PUB-ENTRY">
        <!-- This rule will fire for all PUB-ENTRY elements that does not 
have a NOTICE grandchild -->
    </sch:rule>
</sch:pattern>

Since only one rule can fire for the PUB-ENTRY context the second rule will 
not fire if the first rule is true. The rules are evaluated in the order 
they appear in the schema so of you turn them around and declare the 
<sch:rule context="PUB-ENTRY"> rule first this won't work because then the 
other rule will never fire. You can think of this in terms of an if-else if 
chain in a progrmming language. You always start with the most restrictive 
rule and then at the end you have a rule that catch everything that isn't 
matched by the first rules.

Hope this helps,
/Eddie

>
><rule context="PUB-ENTRY/BIB/NOTICE"> matches only scenario 1.
><rule context="PUB-ENTRY"> matches scenario 1 *and* 2.
><rule context="PUB-ENTRY and not(BIB/NOTICE)> matches only scenario 2, but
>throws an error.
>
>I hope this is clearer...
>
>Thanks again,
>Allison
>
>
>-----Original Message-----
>From: Chad Williamson [mailto:[email protected]]
>Sent: Friday, January 16, 2004 6:57 PM
>To: Denny, Allison (LNG-BET)
>Cc: '[email protected]'
>Subject: Re: [Schematron-love-in] XPath question
>
>
>
>
>Hi Allison.
>
>I'm a little unclear on exactly what you need to do here.  Perhaps you can
>send
>to sample xml snippets so I can better see what you are trying to
>accomplish.(Although I won't be able to respond until Monday.)
>
>What I have done myself is set up multiple rule contexts each with their 
>own
>assert/reports in them.  Only the valid case will trigger the checks.
>
>I also have created large assert/report with many conditions, if this
>attribute
>="xxx" and this other attribute="yyy", or if sub-element exists and
>ancestor::zzz/@aaa exists.
>
>Perhaps what you are looking for is in these XPATH expressions:
>http://www.w3.org/TR/xpath#location-paths
>
>I hope this helps, chad the rad dad
>
>____________________________________________________________
>
>Chad Williamson, B.Sc. CE                                    BOW Networks
>Inc.
>Software Developer                                                 #200,
>550-71
>Avenue S.E.
>TEL: (403) 640-8422
>Calgary,
>Alberta
>FAX: (403) 253-8979                                                  T2H 
>0S6
>e-mail: [email protected]
>----------------------------------------------------------------------------
>-----------------------------
>
>
>
>
>
>
>"Denny, Allison (LNG-BET)" <[email protected]> on 16/01/2004
>04:32:17
>PM
>
>To:   "'[email protected]'"
>       <[email protected]>
>cc:    (bcc: Chad Williamson/BOW Software Inc.)
>
>Subject:  [Schematron-love-in] XPath question
>
>
>
>
>Hello,
>
>I'd like to create one schematron template that treats the same element
>differently based on the presence of a child.  If the element has a certain
>daughter, there are two validations.  If not, the same element has more
>validations.  But I don't seem to be able to create a <rule> element
>containing a 'not', and I can't think how else to do this.  Can anyone 
>help?
>
><rule context="PUB-ENTRY/BIB/NOTICE[@WITH-DOCUMENT='NO']"> is fine
><rule context="PUB-ENTRY and not(BIB/NOTICE[@WITH-DOCUMENT='NO'])> throws 
>an
>error
><rule context="PUB-ENTRY"> + <rule
>context="PUB-ENTRY/BIB/NOTICE[@WITH-DOCUMENT='NO']"> incorrectly runs all
>validations
>
>Thanks in advance!
>Allison Denny
>
>XML data analyst
>LexisNexis
>
>
>-------------------------------------------------------
>The SF.Net email is sponsored by EclipseCon 2004
>Premiere Conference on Open Tools Development and Integration
>See the breadth of Eclipse activity. February 3-5 in Anaheim, CA.
>http://www.eclipsecon.org/osdn
>_______________________________________________
>Schematron-love-in mailing list
>[email protected]
>https://lists.sourceforge.net/lists/listinfo/schematron-love-in
>
>
>
>
>
>-------------------------------------------------------
>The SF.Net email is sponsored by EclipseCon 2004
>Premiere Conference on Open Tools Development and Integration
>See the breadth of Eclipse activity. February 3-5 in Anaheim, CA.
>http://www.eclipsecon.org/osdn
>_______________________________________________
>Schematron-love-in mailing list
>[email protected]
>https://lists.sourceforge.net/lists/listinfo/schematron-love-in

_________________________________________________________________
MSN 8 with e-mail virus protection service: 2 months FREE* 
http://join.msn.com/?page=features/virus



-------------------------------------------------------
The SF.Net email is sponsored by EclipseCon 2004
Premiere Conference on Open Tools Development and Integration
See the breadth of Eclipse activity. February 3-5 in Anaheim, CA.
http://www.eclipsecon.org/osdn