Validating Individual Attributes


XSLT 2.0 also allows you to request validation at the level of individual attributes. The <xsl:attribute> instruction, like <xsl:element>, has attributes validation and type, which can be used to validate an attribute node independently of its containing element.

It's relatively unusual for a schema to contain global attribute declarations, so the options «validation=" strict" » and «validation=" lax" » are unlikely to be very useful at the attribute level. Also, because attributes don't have children, the options «validation="strip" » and «validation="preserve" » both mean the same thing: The new attribute node will be annotated as «xdt:untypedAtomic ». The most useful option for attributes is to specify «type » to validate the attribute value against a specific type definition in the schema. This will always be the name of a simple type, and in many cases it will be the name of a built-in atomic type, for example «type="xs:date" » or «type="xs:ID" ». But it can also be a list or union type, for example «type="xs:IDREFS" ».

If «xsl:copy » or «xsl:copy-of » is used to create attribute nodes by copying nodes from a source document, attribute-level validation can be invoked using the validation and type attributes in the same way. Unlike the situation with elements, «preserve="yes" » on either of these instructions means what it says: The attribute is copied together with its type annotation.

At the time of writing this chapter, there are gaps in the language specification concerning the validation of attributes whose type is xs:QName or xs:NOTATION. Since these types require a namespace context to perform the validation, it doesn't really make sense to validate standalone attributes that have these types.




XSLT 2.0 Programmer's Reference
NetBeansв„ў IDE Field Guide: Developing Desktop, Web, Enterprise, and Mobile Applications (2nd Edition)
ISBN: 764569090
EAN: 2147483647
Year: 2003
Pages: 324

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net