[Date Prev] | [Thread Prev] | [Thread Next] | [Date Next] -- [Date Index] | [Thread Index] | [Elist Home]
Subject: Simplifying interleaved optional patterns
Hi, In the RELAX NG schema for XML Schema, and in the one I'm working on now, there are several situations where an attribute takes a list of tokens, each token being one of an enumerated set. For example, a block attribute in XML Schema is a list of the tokens 'restriction', 'extension', 'substitution'. It's easy to say that in RELAX NG: <list> <zeroOrMore> <choice> <value type="token">restriction</value> <value type="token">extension</value> <value type="token">substitution</value> </choice> </zeroOrMore> </list> But I want to say that each one of the tokens can only appear once, and that they can appear in any order. I think the only way to do this is: <list> <interleave> <optional> <value type="token">restriction</value> </optional> <optional> <value type="token">extension</value> </optional> <optional> <value type="token">substitution</value> </optional> </interleave> </list> Is there an easier way to do this? The main annoyance of this method is that you can't define all the possible tokens in one named pattern and then just refer to that. I don't know if it would be possible to have a shorthand like: <list> <options> <value type="token">restriction</value> <value type="token">extension</value> <value type="token">substitution</value> </options> </list> where <options>p1 p2</options> maps to <interleave><optional>p1</optional><optional>p2</optional></interleave> Something like this could also simplify situations where you have lots of optional attributes. For example (from the XML Schema schema): <element name="schema" doc:href="http://www.w3.org/TR/xmlschema-1/#element-schema"> <ref name="openAttrs" /> <optional> <attribute name="version"><data type="token" /></attribute> </optional> <optional> <attribute name="finalDefault"> <ref name="derivationSet" /> </attribute> </optional> <optional> <attribute name="blockDefault"> <ref name="blockSet" /> </attribute> </optional> <optional> <attribute name="attributeFormDefault"> <ref name="formChoice" /> </attribute> </optional> <optional> <attribute name="elementFormDefault"> <ref name="formChoice" /> </attribute> </optional> <optional> <attribute name="id"><data type="ID" /></attribute> </optional> <optional> <attribute name="xml:lang"> <data type="language" /> </attribute> </optional> ... </element> could become: <element name="schema" doc:href="http://www.w3.org/TR/xmlschema-1/#element-schema"> <ref name="openAttrs" /> <options> <attribute name="version"><data type="token" /></attribute> <attribute name="finalDefault"> <ref name="derivationSet" /> </attribute> <attribute name="blockDefault"> <ref name="blockSet" /> </attribute> <attribute name="attributeFormDefault"> <ref name="formChoice" /> </attribute> <attribute name="elementFormDefault"> <ref name="formChoice" /> </attribute> <attribute name="id"><data type="ID" /></attribute> <attribute name="xml:lang"> <data type="language" /> </attribute> </options> ... </element> (Although actually I guess I could do a zeroOrMore/choice in this situation, given that I know that attributes can't be repeated.) Cheers, Jeni --- Jeni Tennison http://www.jenitennison.com/
[Date Prev] | [Thread Prev] | [Thread Next] | [Date Next] -- [Date Index] | [Thread Index] | [Elist Home]
Powered by eList eXpress LLC