Schematron rule validation

Here should go questions about transforming XML with XSLT and FOP.
nandu
Posts: 2
Joined: Mon Aug 18, 2008 1:25 pm

Schematron rule validation

Post by nandu »

Dear All,

I am very new to the group and schematron and would need your help in order to debug an issue. I have got a sample xml file as follows:
<A>
<Items>
<Item no=1>
<Amount>0</Amount>
</Item>
<Item no=2>
<Amount>10</Amount>
</Item>
</Items>
</A>

I need to write a rule that should raise an error only when all Amount element's value is 0. I have written the following schematron snippet:

<sch:pattern name="Correct Amount">
<sch:rule context="/A/Items/Item/Amount">
<sch:assert test="normalize-space(.)!='0'">
All Amount must not be zero
</sch:assert>
</sch:rule>
</sch:pattern>

This works if both the amount is 0. But if one is 0 and the other non-zero, this doesn't work.

Any idea what the correct rule should be?

Thanks very much.
sorin_ristache
Posts: 4141
Joined: Fri Mar 28, 2003 2:12 pm

Re: Schematron rule validation

Post by sorin_ristache »

Hello,

The rule should be like:

Code: Select all

  <sch:pattern>
<sch:rule context="/A/Items">
<sch:assert test="count(Item/Amount[. != 0]) > 0">
All Amount must not be zero
</sch:assert>
</sch:rule>
</sch:pattern>
Regards,
Sorin
nandu
Posts: 2
Joined: Mon Aug 18, 2008 1:25 pm

Re: Schematron rule validation

Post by nandu »

Dear Sorin,

Thank you very much. This is working now.

Regards.
Post Reply