Hi Dave,
Not only attach, but also unwrap to ignore sections you do not want but
process further sections inside them.
Here it is an example.
The problem:
We want to validate from a document like below
<?oxygen NVDLSchema="test.nvdl"?>
<sample:test xmlns:sample="http://sample">
<sample:a>
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<sample:b>
<xsl:template match="/">
</xsl:template>
</sample:b>
</xsl:stylesheet>
</sample:a>
</sample:test>
each namespace fragment against its schema, equivalent with validating
two documents:
<sample:test xmlns:sample="http://sample">
<sample:a>
<sample:b>
</sample:b>
</sample:a>
</sample:test>
against sample.xsd
and
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:template match="/">
</xsl:template>
</xsl:stylesheet>
against xslt.rng.
Here it is the NVDL script, discussed below.
<?xml version="1.0" encoding="UTF-8"?>
<rules xmlns="http://purl.oclc.org/dsdl/nvdl/ns/structure/1.0"
startMode="sample">
<mode name="sample">
<namespace ns="http://sample">
<validate schema="sample.xsd" useMode="getAllSample"/>
<unwrap useMode="xslt"/>
</namespace>
</mode>
<mode name="xslt">
<namespace ns="http://www.w3.org/1999/XSL/Transform">
<validate schema="xslt.rng" useMode="getAllXSLT"/>
</namespace>
</mode>
<mode name="getAllSample">
<namespace ns="http://sample"><attach/></namespace>
<anyNamespace><unwrap/></anyNamespace>
</mode>
<mode name="getAllXSLT">
<namespace
ns="http://www.w3.org/1999/XSL/Transform"><attach/></namespace>
<anyNamespace><unwrap/></anyNamespace>
</mode>
</rules>
We start with the sample mode. That allows only elements from the sample
schema to start the document, the default anyNamespace rule will reject
any other namespace. So if we will have the root from the sample
namespace then it will start a section that will contain all the
elements from the sample namespace that have a parent in the same
namespace, in our case the section will contain
<sample:test>
<sample:a>
We apply two actions on this, validate and unwrap. Let's consider each
one of these below.
1. validate.
The validate action will process the content below this section using
the mode getAllSample. In the getAllSample mode we attach all the
sections that match the sample namespace and we unwrap (ignore) content
in other namespaces. The next section will be
<xsl:stylesheet>
This will be matched by the anyNamespace rule from the getAllSample mode
that will ignore it through the unwrap action. The unwrap action does
not explicitly specify a useMode so it will use the same mode getAllSample.
The next section is
<sample:b>
This will be matched by the namespace rule and the attach action will be
executed, thus attaching <sample:b> to the initial section, giving:
<sample:test>
<sample:a>
<sample:b>
to be validated against the sample.xsd schema.
Further the attach action also does not specify a mode to be used
further so we remain at the getAllSampleMode and the next section is
<xsl:template>
that will be ignored by the unwrap action from the anyNamespace rule.
Let's move to the second action.
2. unwrap
This ignores the initial section from the sample namespace and uses the
mode xslt further.
The next section
<xsl:stylesheet>
will be matched in the xslt mode by the namespace rule matching the XSLT
namespace. This will invoke a validate action on the XSLT section using
further the mode getAllXSLT.
This getAllXSLT mode is similar with the getAllSample mode, it will
attach XSLT section while ignoring sections from other namespaces. So it
will ignore in our case the sample:b element while attaching the
xsl:template.
Hope this helps,
George
---------------------------------------------------------------------
George Cristian Bina
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com
Dave Pawson wrote:
> On 23/02/07, George Cristian Bina <george@oxygenxml.com> wrote:
>
>> >> Note that if you can obtain a valid XSLT by removing elements from
>> other
>> >> namespaces and attributes from your document then you can use NVDL to
>> >> build this XML fragment and validate it with your schema.
>> > Sorry I don't understand that sentance.
>>
>> If you have something like
>>
>> <sample:test xmlns:sample="sample">
>> <sample:a>
>> <xsl:stylesheet xmlns:xsl="">
>> <sample:b>
>> <xsl:template match="/">
>> </xsl:template/>
>> </sample:b>
>> </xsl:stylesheet>
>> </sample:a>
>> </sample:test>
>>
>> Then you can obtain an XSLT document by removing all the elements from
>> the sample namespace
>> <xsl:stylesheet xmlns:xsl="">
>> <xsl:template match="/">
>> </xsl:template/>
>> </xsl:stylesheet>
>
> Yes....
>
>
>> In this case it should be possible to write an NVDL script that gets all
>> the XSLT content by attaching all XSLT sections each up to the previous
>> one and that validates the whole XSLT fragment against the XSLT schema.
>
> So the nvdl schema uses 'attach' to do that? to pass validation up the
> mode tree
> to the ancestor that validates against the xslt schema?
>
>>
>> [...]
>> >> For instance you can have a
>> >> schema for XSLT that defines all XSLT elements, each allowing any
>> XSLT
>> >> element inside.
>
> Which is the model you have above...
>
>
>> > I *think* that would have been too loose for what I wanted?
>>
>> Probably, it depends on what you want :). But from a previous email from
>> you (a private email I think) I remember that you may have as input
>> xsl:choose without an xsl:when or xsl:otherwise - so it is more to
>> change in the XSLT schema than only to add more start elements.
>> Recalling that discussion I think the solution I suggested then was to
>> make all the required content optional.
>
> Ok. I've got the idea. If attach is the key to this solution I can
> try it with a simple model first.
>
> Thanks George.
>
> Have a good weekend.
>
> regards
>
>
>
>
>
-- 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 Fri Feb 23 22:09:42 2007
This archive was generated by hypermail 2.1.8 : Sat Feb 24 2007 - 07:38:03 UTC