W3C home > Mailing lists > Public > www-forms@w3.org > November 2002

XForms and xsd:ID

From: Mark Seaborne <MSeaborne@origoservices.com>
Date: Thu, 28 Nov 2002 12:24:51 -0000
Message-ID: <DC65AE678B89004B9CCB202E19482CC704FB8A@mail.origoservices.local>
To: <www-forms@w3.org>


For the last few days I have been working on an XForms form that has to work with XML that includes attributes of type xsd:ID.

The XML is really simple:

	<my_element id="a1">source</my_element>
	<my_element id="a2">Bob</my_element>
	<my_element id="a3">Harry</my_element>

So is the schema:

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" attributeFormDefault="unqualified">
	<xs:element name="my_root">
				<xs:element name="my_element" maxOccurs="unbounded">
							<xs:extension base="xs:string">
								<xs:attribute name="id" type="xs:ID" use="required"/>

I built a form that included the following trigger:

<xfm:trigger id="insertbutton">
	<xfm:action ev:event="click">
		<xfm:insert nodeset="/my_root/my_element" at="xfm:index('element')" position="after"/>

I wondered what would happen to the required @id of type xsd:ID when I did an <insert/>. It has been pointed out to me that the CR says (Section 9.3.5) that "nodes of type xsd:ID are not copied" when <insert/> is used.

Well, both X-Smiles and the Novell browser do copy the id attributes, but not their values.

I am not sure whether this is correct or not.

Regardless of whether they should not copy the attributes, or just not the values, I end up with an invalid instance.

Remembering my XSLT, I thought, I know I will put in a binding to automatically generate an id, like so:

<xfm:bind nodeset="//@id" calculate="generate-id()"/>

This works nicely in X-Smiles, it just generates new id values for all my id attributes and stops <insert/> from generating invalid XML.

However, it has now been pointed out to me that generate-id() is not an XPath function, but an XSLT function, so I suppose X-Smiles is perhaps being over-generous in offering it to me.

So, how to generate unique values of type xsd:id? It doesn't seem an unreasonable thing to want to do, indeed to properly support the XML structures we use here, it may be a prerequisite for adoption of XForms. 

I don't really see why XForms cannot take a leaf out of XSLT's book, and provide a mechanism for generating xsd:ID values. To be honest, I cannot really see why an <insert/> or a <copy/> couldn't just generate id values automatically (invoke generate-id() as a default behaviour). But even if this is undesirable for some reason, generate-id() would be a valuable addition to the XForms function set.

If anyone can think of an alternative way of generating id values please let me know. I assumed that the form author would not know in advance how many times a node of type xsd:ID might repeat, so values cannot be hardcoded into the form. I did try using various data/time functions with concat() to try to generate unique values, but X-Smiles just wasn't slow enough!

So that is xsd:ID. What about uniqueness in schemas? what should happen if I try to insert a structure that has something declared as unique within it? One wouldn't expect unique values to be generated, but what should happen?

All the best

Mark Seaborne
Received on Thursday, 28 November 2002 07:25:16 UTC

This archive was generated by hypermail 2.3.1 : Tuesday, 6 January 2015 21:36:07 UTC