Validating a Temporary Tree


In the previous two sections, we have seen how you can validate a source document that is to be processed by the stylesheet, and how you can validate result documents produced as output by the stylesheet. It's also possible to apply validation to temporary documents created and used internally during the course of stylesheet processing (these documents are known as temporary trees).

The most common way to create a temporary tree is as follows :

  <xsl:variable name="temp">   <xsl:apply-templates select="." mode="phase-1"/>   </xsl:variable>  

There is no «as » attribute here: the default type for a variable whose value is defined by a contained sequence constructor, rather than by means of a select attribute, is document-node() , which means that the value of the variable will be the document node at the root of a newly constructed temporary tree. The body of the tree in this case is produced by the <xsl: apply-templates> instruction.

The example above can be regarded as shorthand for the more detailed construction:

  <xsl:variable name="temp" as="document-node()">   <xsl:document>   <xsl:apply-templates select="." mode="phase-1"/>   </xsl:docutnent>   </xsl:variable>  

This shows more explicitly how the sequence constructor contained in the <xsl:variable> element creates a single document node, whose content is populated by the <xsl:apply-templates> instruction.

If you expand the variable definition in this way, you can also use the attributes validation and type on the <xsl:document> instruction to invoke validation of the temporary tree. These attributes work exactly the same way on <xsl:document> as they do on <xsl:result-document>, which produces a final result tree.

Another way of creating temporary trees is by copying an existing document node using either of the instructions <xsl:copy> (which makes a shallow copy) or <xsl:copy-of> (which makes a deep copy). These instructions both have validation and type attributes, and when the instructions are used to copy a document node, these attributes work the same way as the corresponding attributes on the <xsl:document> and <xsl:result-document> instructions.




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