Frage

I've recently started using schematron to validate xml documents. I'm pretty impressed by it so far, but I've stumbled upon a rule that I can't get to work properly.

I've made a simple example below.

<iso:assert test="ns1:some-element/text() = 'false' and /ns1:same-other-element">Error message</iso:assert>

Basically I want to validate two things, if ns1:some-element/text() contains 'false', ns1:same-other-element should be present, and that validation actually works. However, when ns1:some-element/text() contains something other than false, than I don't care weather ns1:same-other-element is there or not.

At this moment, the rule also fires when ns1:same-other-element is missing and the value of ns1:some-element/text() is not 'false'

Any ideas how to work around this?

War es hilfreich?

Lösung

Your test needs to evaluate to true in order to pass validation (you are making an assertion about something). What you are currently saying with your condition is: the text node of ns1:some-element MUST have a value of 'false' AND ns1:some-other-element MUST exist. Anything else is an error.

The condition you are probably looking for is

<iso:assert test="ns1:some-element = 'false' and /ns1:same-other-element or ns1:some-element != 'false'">Error message</iso:assert>

This condition will be true whenever ns1:some-element has a value that is not 'false', regardless of whether ns1:some-other-element is present.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top