W3C home > Mailing lists > Public > xmlschema-dev@w3.org > August 2010

Re: kind of mixed (and ordered) content

From: Mukul Gandhi <gandhi.mukul@gmail.com>
Date: Tue, 3 Aug 2010 06:20:37 +0530
Message-ID: <AANLkTinGxTBENK=PN5hi5GNO4O7CFxWteCCe4fgc-z30@mail.gmail.com>
To: xmlschema-dev@w3.org
Cc: matthieu.ricaud@igs-cp.fr
I believe this list is about W3C XML Schema.

I'm not sure how this could be done with RELAX NG.

But it should be possible to write such a validation constraint with
XSD 1.1 (it's still not a REC) assertions. An example of this is
below:

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">

	<xs:element name="span">
	     <xs:complexType mixed="true">
	           <xs:sequence>
		        <xs:element name="a" type="LINK" maxOccurs="unbounded" />
	           </xs:sequence>
	           <xs:attribute name="class" type="xs:string" />
	           <xs:assert test="text()[preceding-sibling::a[1] and
following-sibling::a[1]][. = ', ']
		                              and
					    normalize-space(a[1]/preceding-sibling::text()) = '' and
					    normalize-space(a[last()]/following-sibling::text()) = ''" />
	     </xs:complexType>
	</xs:element>
	
	<xs:complexType name="LINK">
	     <xs:simpleContent>
	          <xs:extension base="xs:string">
		      <xs:attribute name="href" type="xs:anyURI" />
		  </xs:extension>
	     </xs:simpleContent>
	</xs:complexType>
	
</xs:schema>

The assertion in above schema specifies:
1. Any two <a> have ", " in between
2. The first and last <a> can be preceded and followed (respectively)
only by white-space's.


On Mon, Aug 2, 2010 at 7:57 PM, Matthieu Ricaud-Dussarget
<matthieu.ricaud@igs-cp.fr> wrote:
> ** The constraint **

> is a restriction on xhtml elements. I need to say : "this span contain a
> serie of links separated by a coma and a space"
> that is :
> <span class="foo">
>     <a href="#1">1</a>,&#160;
>     <a href="#2">2</a>,&#160;
>     <a href="#3">2</a>,&#160;
> </span>
> (well it would be even better if the last <a> has no text after but let say
> I don't care about that)




-- 
Regards,
Mukul Gandhi
Received on Tuesday, 3 August 2010 00:51:30 UTC

This archive was generated by hypermail 2.4.0 : Friday, 17 January 2020 23:15:57 UTC