XML.orgXML.org
FOCUS AREAS |XML-DEV |XML.org DAILY NEWSLINK |REGISTRY |RESOURCES |ABOUT
OASIS Mailing List ArchivesView the OASIS mailing list archive below
or browse/search using MarkMail.

 


Help: OASIS Mailing Lists Help | MarkMail Help

[Date Prev] | [Thread Prev] | [Thread Next] | [Date Next] -- [Date Index] | [Thread Index]
Re: [xml-dev] Using Schematron to express a rule for a QName value?

At 2012-09-21 15:40 +0000, Costello, Roger L. wrote:
>Hi Folks,
>
>Consider the following XML document. There is an <Item> element 
>which has a "name" attribute:
>
><Test xmlns:wid="http://www.widget.org";>
>     <Item name="wid:widget" />
></Test>
>
>The value of  @name is a QName.
>
>I want a Schematron rule that expresses this:
>
>       The <Item> element must have a
>       name attribute whose value is "widget"
>       in the http://www.widget.org namespace.
>       (The value of @name is a QName)
>
>So I created this Schematron document:
>
><sch:schema xmlns:sch="http://purl.oclc.org/dsdl/schematron";
>                         xmlns:xsd="http://www.w3.org/2001/XMLSchema";
>                         xmlns:w="http://www.widget.org";
>                        queryBinding="xslt2">
>
>    <sch:pattern id="QName-Test">
>
>       <sch:rule context="Item">
>
>          <sch:assert test="resolve-QName(@name, .)  eq 
> xsd:QName('w:widget')">
>                The value of the name attribute must
>                be 'widget' in the http://www.widget.org
>                namespace.
>          </sch:assert>
>
>       </sch:rule>
>
>    </sch:pattern>
>
></sch:schema>
>
>When I validated the XML document against the Schematron schema I 
>got this error:
>
>       Namespace prefix {w} has not been declared
>
>Any ideas on what the problem is?

You are missing a Schematron namespace declaration:

   <sch:ns prefix="w" uri="http://www.widget.org"/>

While it may appear you have satisfied the binding in the Schematron 
schema expression, when this gets translated to XSLT there is nothing 
in the Schematron specification that migrates in-scope namespace 
declarations automatically to the runtime artefact that does the 
actual validation.  Thus, by the time the XSLT of the compiled schema 
is running, the XPath expression with the prefix does not have a 
binding in scope.

The explicit Schematron namespace declaration is meant to address that.

I hope this helps.

. . . . . . . . Ken

--
Contact us for world-wide XML consulting and instructor-led training
Free 5-hour lecture: http://www.CraneSoftwrights.com/links/udemy.htm
Crane Softwrights Ltd.            http://www.CraneSoftwrights.com/x/
G. Ken Holman                   mailto:gkholman@CraneSoftwrights.com
Google+ profile: https://plus.google.com/116832879756988317389/about
Legal business disclaimers:    http://www.CraneSoftwrights.com/legal



[Date Prev] | [Thread Prev] | [Thread Next] | [Date Next] -- [Date Index] | [Thread Index]


News | XML in Industry | Calendar | XML Registry
Marketplace | Resources | MyXML.org | Sponsors | Privacy Statement

Copyright 1993-2007 XML.org. This site is hosted by OASIS