RE: XPath question
"Denny, Allison (LNG-BET)" <[email protected]> Wed, 28 Jan 2004 16:37:12 -0500
| Newsgroups | gmane.text.xml.schematron |
|---|---|
| Message-ID | <38A60BEBEF60234CB599A1FD4BE466E501186071@lnxbetexch00.lexis-nexis.com> |
Edvard, thank you very much for this. I did not realize that ordering was significant. -----Original Message----- From: Edvard Robertsson [mailto:[email protected]] Sent: Sunday, January 18, 2004 7:20 AM To: [email protected]; [email protected] Cc: [email protected] Subject: RE: [Schematron-love-in] XPath question 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 ------------------------------------------------------- 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