Re: Attribute Fixed and Prohibited

Hi Joey,

> I want an attribute to have a fixed value that is available to the
> schema processor, but not allow the attribute in instances. Is the
> following valid, and does it do what I want.
>
> <xs:attribute name="domain" type="xs:positiveInteger" use="prohibited" 
> fixed="123"/>

The use="prohibited" attribute is a way of removing attribute uses
from the set of attributes for a complex type when you derive by
restriction. It bans the attribute from appearing in the instance, but
it also means that the attribute isn't present in the PSVI, so you
won't have access to the fixed value at all.

I don't think that there is a way of doing what you describe. I guess
that you could say that the attribute is optional (the default), with
a fixed value:

  <xs:attribute name="domain" type="xs:positiveInteger" fixed="123"/>

And then have a Schematron rule that tests whether it's actually
present:

  <sch:report test="@domain">
    The domain attribute should not be present.
  </sch:report>

This will only work if you're using Schematron with XSLT 1.0; come
XSLT 2.0, XSLT will work over the PSVI, so won't be able to tell the
difference between an attribute that's actually present in the
document and one that's been fixed or defaulted in the schema.

Out of interest, why do you want to do this, and how are you intending
that the fixed attribute be used by applications? If you want to
provide a kind of "annotation" about an element, I suggest that you
use xs:appinfo instead:

  <xs:appinfo>
    <my:domain>123</my:domain>
  </xs:appinfo>

Applications with access to the PSVI should get access to the content
of xs:appinfo in order to get this value; since it's not declared as
an attribute, there's no risk of it appearing in the instance
document.

Cheers,

Jeni

---
Jeni Tennison
http://www.jenitennison.com/

Received on Wednesday, 27 March 2002 08:23:49 UTC