[dsdl-comment] Re: Are these two NVDL documents equivalent? (one usesa mode, the other doesn't use a mode)

From: George Cristian Bina <george@oxygenxml.com>
Date: Mon May 12 2008 - 13:44:45 UTC

You should think of NVDL in terms of XSLT processing, the rules can be
thought as XSLT templates. In fact, in the XSLT 2.0 implementation of
the NVDL dispatching from oNVDL they are converted exactly to templates.

Here it is what the oNVDL XSLT 2.0 implementation does if we take the A
inside B sample:

<?xml version="1.0" encoding="UTF-8"?>
<b xmlns="http://www.B.org">
     <a xmlns="http://www.A.org"/>
</b>

It creates the namespace sections putting a section element for each
namespace:

<?xml version="1.0" encoding="UTF-8"?>
<n:section xmlns:n="http://www.oxygenxml.com/nvdl" ns="http://www.B.org">
    <b xmlns="http://www.B.org">
       <n:section ns="http://www.A.org">
          <a xmlns="http://www.A.org"/>
       </n:section>
    </b>
</n:section>

The NVDL script

<?xml version="1.0"?>
<rules startMode="start"
     xmlns="http://purl.oclc.org/dsdl/nvdl/ns/structure/1.0">
     <mode name="start">
         <namespace ns="http://www.A.org">
             <validate schema="A.xsd" />
         </namespace>
         <namespace ns="http://www.B.org">
             <validate schema="B.rng"/>
         </namespace>
     </mode>
</rules>

is converted automatically by an XSLT stylesheet into the following
stylesheet, note the templates matching sections for each namespace:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:n="http://www.oxygenxml.com/nvdl" version="2.0"
exclude-result-prefixes="n">
    <xsl:output indent="yes"/>
    <xsl:template match="/">
       <n:dispatch>
          <xsl:variable name="content">
             <xsl:apply-templates mode="mode_start"/>
          </xsl:variable>
          <xsl:apply-templates mode="flatten" select="$content"/>
       </n:dispatch>
    </xsl:template>
    <xsl:template mode="mode_start"
match="n:section[@ns='http://www.A.org']">
       <n:validate schema="A.xsd">
          <xsl:apply-templates mode="mode_start"/>
       </n:validate>
    </xsl:template>
    <xsl:template mode="mode_start"
match="n:section[@ns='http://www.B.org']">
       <n:validate schema="B.rng">
          <xsl:apply-templates mode="mode_start"/>
       </n:validate>
    </xsl:template>
    <xsl:template match="n:section" mode="mode_start">
       <n:reject>
          <xsl:apply-templates mode="mode_start"/>
       </n:reject>
    </xsl:template>
    <xsl:template
match="*[namespace-uri()!='http://www.oxygenxml.com/nvdl']" mode="#all"
       priority="-100">
       <xsl:copy>
          <xsl:apply-templates
select="@*[namespace-uri()!='http://www.oxygenxml.com/nvdl']"
             mode="#current"/>
          <xsl:apply-templates select="@n:*" mode="#current"/>
          <xsl:apply-templates mode="#current"/>
       </xsl:copy>
    </xsl:template>
    <xsl:template
match="@*[namespace-uri()!='http://www.oxygenxml.com/nvdl']" mode="#all"
       priority="-100">
       <xsl:copy/>
    </xsl:template>
    <xsl:template match="@n:*" mode="#all" priority="-100"/>
    <xsl:template match="*" mode="flatten">
       <xsl:apply-templates select="//n:*" mode="flatten1"/>
    </xsl:template>
    <xsl:template match="n:*" mode="flatten1">
       <xsl:copy>
          <xsl:copy-of select="@*"/>
          <xsl:apply-templates
select="text()|*[namespace-uri()!='http://www.oxygenxml.com/nvdl']"
             mode="flatten2"/>
       </xsl:copy>
    </xsl:template>
    <xsl:template
match="*[namespace-uri()!='http://www.oxygenxml.com/nvdl']" mode="flatten2">
       <xsl:copy>
          <xsl:copy-of
select="@*[namespace-uri()!='http://www.oxygenxml.com/nvdl']"/>
          <xsl:apply-templates
select="text()|*[namespace-uri()!='http://www.oxygenxml.com/nvdl']"
             mode="flatten2"/>
       </xsl:copy>
    </xsl:template>
</xsl:stylesheet>

Then the above XSLT applied on the document containing the sections
gives the final dispatching:

<?xml version="1.0" encoding="UTF-8"?>
<n:dispatch xmlns:n="http://www.oxygenxml.com/nvdl">
    <n:validate schema="B.rng">
       <b xmlns="http://www.B.org">

    </b>
    </n:validate>
    <n:validate xmlns="http://www.B.org" schema="A.xsd">
          <a xmlns="http://www.A.org"/>
       </n:validate>
</n:dispatch>

Best Regards,
George

--
George Cristian Bina
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com
Dave Pawson wrote:
> Hi George.
> 
> 2008/5/12 George Cristian Bina <george@oxygenxml.com>:
>> Hi Dave,
>>
>>  No, any namespace can appear first, any of the two namespace rules can
>> match the initial section. To have B allowed only inside A then you need
>> something like below:
>>
>>
>>  <?xml version="1.0"?>
>>  <rules startMode="start"
>>     xmlns="http://purl.oclc.org/dsdl/nvdl/ns/structure/1.0">
>>     <mode name="start">
>>         <namespace ns="http://www.A.org">
>>             <validate schema="A.xsd" >
>>                 <mode>
>>
>>                     <namespace ns="http://www.B.org">
>>                         <validate schema="B.rng"/>
>>                     </namespace>
>>                 </mode>
>>             </validate>
>>         </namespace>
>>     </mode>
>>  </rules>
> 
> 
> Doh!
> 
> Obvious... when I'm told about it :-(
> 
> I was thinking procedurally, that the mode indicated from the
> startMode *must* come first for validity.
> 
> I find my reasoning here 'intuitively' right (even if wrong!!!)
> 
> 
> 
> Thanks George.
> 
> 
> 
--
DSDL comments
To unsubscribe, please send a message with the
command  "unsubscribe" to dsdl-comment-request@dsdl.org
(mailto:dsdl-comment-request@dsdl.org?Subject=unsubscribe)
Received on Mon May 12 15:44:56 2008

This archive was generated by hypermail 2.1.8 : Mon May 12 2008 - 14:13:04 UTC