Page 1 of 1

triggers

Posted: Wed Aug 08, 2007 5:59 am
by queshaw
Do triggers allow you to validate elements in the same namespace using different schemas? If so, how do you specify which schema to use for the different sections?

Posted: Thu Aug 09, 2007 6:51 am
by queshaw
After seeing how the context element works (hopefully), I tried using triggers again and it seems to work (allow validation of an element in the same namespace using a different schema):

a.rnc:

namespace a = "http://a"
start = root
root = element a:doc { section+ }
section = element a:section { p+ }
p = element a:p { empty }

b.rnc:

namespace a = "http://a"
start = element a:quote { text }

an.nvdl:

<?xml version="1.0" encoding="UTF-8"?>
<rules xmlns="http://purl.oclc.org/dsdl/nvdl/ns/structure/1.0" schemaType="application/x-rnc"
startMode="a">
<trigger ns="http://a" nameList="quote"/>
<trigger ns="http://a" nameList="doc section p"/>
<mode name="a">
<namespace ns="http://a">
<validate schema="a.rnc">
<context path="p" useMode="b"/>
</validate>
</namespace>
</mode>
<mode name="b">
<namespace ns="http://a">
<validate schema="b.rnc"/>
</namespace>
</mode>
</rules>

test.xml:

<?xml version="1.0" encoding="UTF-8"?>
<doc xmlns="http://a">
<section>
<p>
<quote>xyz</quote>
</p>
</section>
</doc>

Posted: Thu Aug 09, 2007 1:49 pm
by george
Hi,

The above allows quote only inside p.
Note that you can very well use also something like

Code: Select all


<?xml version="1.0" encoding="UTF-8"?>
<rules xmlns="http://purl.oclc.org/dsdl/nvdl/ns/structure/1.0"
schemaType="application/x-rnc" startMode="a">
<trigger ns="http://a" nameList="quote"/>
<trigger ns="http://a" nameList="doc section p"/>
<mode name="a">
<namespace ns="http://a">
<validate schema="a.rnc" useMode="b"/>
</namespace>
</mode>
<mode name="b">
<namespace ns="http://a">
<validate schema="b.rnc"/>
</namespace>
</mode>
</rules>
This will allow quote inside any of the elements defined in the first schema.

Regards,
George

Posted: Thu Aug 09, 2007 8:25 pm
by queshaw
Thank you for the explanation. In your example, is it the start mode that determines which schema is being used for each section?

For example, this instance would be rejected:

<quote xmlns="http://a"/>

because the start mode results in validation against a.rnc.

If I had a document type in which elements from the name lists in the triggers can't be expected to occur in a specific document order relative to each other, can I still use triggers to dispatch to the different schemata. For example:

a.rnc:

namespace a = "http://a"
start = element a:doc { empty }

b.rnc:

namespace b = "http://b"
start = element b:group { empty }

c.rnc:

namespace b = "http://b"
start = (section|division)
section = element b:section { division? }
division = element b:division { section? }

test1.xml:

<a:doc xmlns:a="http://a" xmlns:b="http://b">
<b:group>
<b:section/>
</b:group>
</a:doc>

test2.xml:

<a:doc xmlns:a="http://a" xmlns:b="http://b">
<b:section>
<b:group/>
</b:section>
</a:doc>

an.nvdl:

<?xml version="1.0" encoding="UTF-8"?>
<rules xmlns="http://purl.oclc.org/dsdl/nvdl/ns/structure/1.0" schemaType="application/x-rnc"
startMode="a">
<trigger ns="http://b" nameList="group"/>
<trigger ns="http://b" nameList="section division"/>
<mode name="a">
<namespace ns="http://a">
<validate schema="a.rnc" useMode="c"/>
</namespace>
</mode>
<mode name="b">
<namespace ns="http://b">
<validate schema="b.rnc" useMode="c"/>
</namespace>
</mode>
<mode name="c">
<namespace ns="http://b">
<validate schema="c.rnc" useMode="b"/>
</namespace>
</mode>
</rules>

allows section or division within doc, but not group within doc.

Posted: Thu Aug 09, 2007 11:05 pm
by george
Hi,

The start mode determines the set if rules that are applied on the root section, on the section that starts with the document root element. Further sections will be processed with the useMode of the actions that apply on the root section - if no useMode is specified then the same mode (set of rules) will be used further.

Triggers do not have an active role in dispatching. They are only used to obtain the element sections from the initial document. Basically the NVDL processing has 3 stages:

- obtaining element and attribute sections from the input document and the set of triggers
- deterniming what actions are applied on each section (interpretations) and getting the validation candidates (document fragments) by attaching and unwrapping sections
- perform the validate actions on the validation candidates

The first 2 processing stages are inplemented also in the oNVDL XSLT 2.0 implementation of NVDL. You may give that a try, you will be able to see the XSLT 2.0 equivalent of an NVDL script that performs the second step from the above description. The 1st step is performed by a stylesheet that converts the input document into an augumented XML document adding the section information.

In your example the root section will be processed with the rules that represent mode a. The child section of the root section will be processed with the modes that compose mode c, that is with:

<namespace ns="http://b">
<validate schema="c.rnc" useMode="b"/>
</namespace>

In both XML input example the second section will be processed with the above rule and the second section is
in the case of test1 <b:group> </b:group>
in the case of test2 <b:section> </b:section>

In both cases teh namespace rule is matched so the section will be validated against the c.rnc schema that does not accept the group element.

Best Regards,
George

Posted: Fri Aug 10, 2007 12:51 am
by queshaw
Thank you. The XSLT looks like that will help answer questions

I read your answer as confirming what I thought might be true.

Effectively, while sections can be dispatched for validation based on namespace, independent of the position of elements relative to each other, sections that are created by triggers need to have their expected order explicitly specified by a sequence of modes.