Using xsi:type


I haven't yet mentioned the use of xsi: type in this chapter (I did mention xsl: type, but that's a completely different thing, despite the similar name ). In fact, the XSLT 2.0 specification mentions xsi: type only in notes and examples, which means that it plays no formal role in the XSLT language.

You can use xsi:type as an attribute on an element within a document that's being assessed by a schema processor. Its effect is to ask the schema processor to apply a stricter check to the element than it would otherwise . An xsi: type can't override the constraints defined in the schema, but it can make assertions about the document content that go beyond what the schema requires. For example, if the schema allows a particular element (by means of a union type) to contain either an integer or a QName, then specifying « xsi: type="xs: QName" » will cause it to be validated as if only a QName were allowed. This can also result in the element node acquiring a more specific type annotation than would otherwise be the case.

The effect of xsi: type on schema validation applies just as much when the validation is happening under the control of XSLT as it does in free-standing schema processing. If you write an xsi: type attribute to the result tree (which you can do in exactly the same way as you write any other attribute), then the element will be validated against that type definition.

Although I started by saying that xsi: type and xsl:type were quite different things, this description shows that there are cases where their effects are very similar. For example, writing:

  <cost xsi:type="xs:decimal">23.44</cost>  

and

  <cost xsl:type="xs:decimal">23.44</cost>  

can both produce a <cost> element validated and annotated as being of type xs: decimal. However, there are some important differences:

  • xsl:type (or type) invokes validation as well as specifying the expected type of the element. xsi:type specifies the expected type, but it is ignored unless validation is requested by some other mechanism.

  • The xsi:type attribute is copied to the result document; the xsl:type and type attributes are not.

  • The xsi:type attribute can only be used to specify the type of element nodes. A type attribute (when it is used on the <xsl: attribute> instruction) can also control the type of attribute nodes.




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