Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
Old December 15th, 2006, 12:47 AM
Authorized User
Join Date: Jun 2006
Posts: 22
Thanks: 0
Thanked 0 Times in 0 Posts
Default Using constrainst on multiple schemas

Hi there,

It is possible to define contraints in a schema that is being referenced. Assuming I have 2 separate schemas namely schemaA and schemaB.

In schemaA, I have an INCLUDE statement to reference to schemaB. And I would like to define the constraints in schemaB to ensure that the unique id is indeed unique.

I understand I can achieve this by defining the constraint in schemaA but I would really like to keep the contraint definition within the respective schema as I may have a few schemas being referenced by schemaA which might get messy. Thanks


<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns="http://www.domain.com.au" targetNamespace="http://www.domain.com.au" elementFormDefault="qualified" attributeFormDefault="unqualified">
    <xs:include schemaLocation="TableSchemas/tscm_location.xsd"/>
    <xs:element name="TDM">
                <xs:element name="tscm_location" type="tscm_location" minOccurs="0" maxOccurs="unbounded"/>


<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" targetNamespace="http://www.domain.com.au" elementFormDefault="qualified">
    <xs:complexType name="tscm_location">
            <xs:element name="locn_id" type="xs:int"/>
            <xs:element name="locn_name" type="xs:string"/>
    <!--<xs:unique name="Constraint1">
    <xs:selector xpath=".//tscm_location"/>
    <xs:field xpath="locn_id"/>

Old December 15th, 2006, 07:08 AM
mhkay's Avatar
Wrox Author
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts

It's a good idea to get the distinction clear between a "schema" and a "schema document". The situation you are describing does not have several schemas, it has a single schema assembled from multiple schema documents.

Identity constraints such as xs:unique are associated with element declarations, and although they are globally named, they have to be written inline within the element declaration. So as far as I'm aware, there's no way of doing what you want - except of course by using non-XSD mechanisms to assemble your schema documents, for example XInclude or plain old external entities.

Michael Kay
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference

Similar Threads
Thread Thread Starter Forum Replies Last Post
XML Schema translation w/ included schemas elliottg XSLT 2 May 16th, 2008 04:14 PM
XML Schemas - Fixed Values jock_sbfc XML 3 February 13th, 2007 07:45 AM
Using XML Schemas in C++ Unmanaged Code RFickling XML 1 June 8th, 2005 08:23 AM
Namespaces, Schemas & XmlSerializer jinjer C# 0 February 3rd, 2005 06:01 AM
Regular expressions in XML schemas adrianbarry XML 10 April 7th, 2004 07:54 AM

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.