Embedded schematron not working in an XML document with a namespace

I'm playing around with some schematron rules embedded in an XSD file. The example is one of the canonical ones, and it works when there are no name spaces involved, but when I introduce a namespace it stops validating and I can't work out why.

The schema is simple:

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
   targetNamespace="http://me.com/ns" xmlns:q="http://me.com/ns">
<xs:element name="socket">
    <xs:annotation>
        <xs:appinfo>
            <sch:pattern name="Mutually exclusive attributes on the socket element"
                xmlns:sch="http://purl.oclc.org/dsdl/schematron">
                <sch:rule context="socket" >
                    <sch:assert test="@hostName and @hostAddress">On a socket element only one
                        of the attributes hostName and hostAddress are allowed, not
                        both.</sch:assert>
                </sch:rule>
            </sch:pattern>
        </xs:appinfo>
    </xs:annotation>
    <xs:complexType>
        <xs:attribute name="hostName" type="xs:string" use="optional"/>
        <xs:attribute name="hostAddress" type="xs:string" use="optional"/>
    </xs:complexType>
</xs:element>
</xs:schema>

and the document being validated is:

<?xml version="1.0" encoding="UTF-8"?>
<socket xmlns="http://me.com/ns" hostAddress="192.168.200.76"/>

The schematron assertion is fired when the namespaces are removed, but as shown above they don't. I tried referencing the namespace in the context, <sch:rule context="q:socket">, but then I get compilation errors from the schematron pipeline.

Does anyone know off the top of their head how to fix this?

Answers


This is an updated XSD that will work:

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns="http://me.com/ns" targetNamespace="http://me.com/ns" xmlns:sch="http://purl.oclc.org/dsdl/schematron">
    <xs:annotation>
        <xs:appinfo>
            <sch:ns uri="http://me.com/ns" prefix="q"/>         
        </xs:appinfo>
    </xs:annotation>
    <xs:element name="socket">
        <xs:annotation>
            <xs:appinfo>
                <sch:pattern name="Mutually exclusive attributes on the socket element" xmlns:sch="http://purl.oclc.org/dsdl/schematron">
                    <sch:rule context="q:socket">
                        <sch:assert test="@hostName and @hostAddress">On a socket element only one
                            of the attributes hostName and hostAddress are allowed, not
                            both.</sch:assert>
                    </sch:rule>
                </sch:pattern>
            </xs:appinfo>
        </xs:annotation>
        <xs:complexType>
            <xs:attribute name="hostName" type="xs:string" use="optional"/>
            <xs:attribute name="hostAddress" type="xs:string" use="optional"/>
        </xs:complexType>
    </xs:element>
</xs:schema>

Schematron requires namespace prefix declarations as indicated above.


Need Your Help

javaFX css styling for an array of text not working

css javafx javafx-css

I have a CSS file that styles my application MusicPlayer. I'm trying to style my array of javafx.scene.text.Text named sliderText. However nothing works. even when i use .text it styles the text of

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.