Sophie

Sophie

distrib > Mageia > 7 > x86_64 > by-pkgid > b3bdfe6d859a3d6920ff2c44b38e9a6f > files > 2976

saxon-manual-9.4.0.9-2.mga7.noarch.rpm

<?xml version="1.0" encoding="iso-8859-1"?>
<?xml-stylesheet href="../make-menu.xsl" type="text/xsl"?><html>
   <head>
      <this-is section="schema-processing" page="satransformapi" subpage=""/>
      <!--
           Generated at 2011-12-09T20:47:22.916Z--><title>Saxonica: XSLT and XQuery Processing: Schema-Aware XSLT from Java</title>
      <meta name="coverage" content="Worldwide"/>
      <meta name="copyright" content="Copyright Saxonica Ltd"/>
      <meta name="title"
            content="Saxonica: XSLT and XQuery Processing: Schema-Aware XSLT from Java"/>
      <meta name="robots" content="noindex,nofollow"/>
      <link rel="stylesheet" href="../saxondocs.css" type="text/css"/>
   </head>
   <body class="main">
      <h1>Schema-Aware XSLT from Java</h1>
      <p>When transformations are controlled using the Java JAXP interfaces, the equivalent to the <code>-val</code>
option is to set the attribute "http://saxon.sf.net/feature/schema-validation" on the TransformerFactory to the
value <a class="bodylink" href="../javadoc/net/sf/saxon/lib/Validation.html#STRICT"><code>net.sf.saxon.lib.Validation.STRICT</code></a>. Alternatively, you can set the value to
         <a class="bodylink" href="../javadoc/net/sf/saxon/lib/Validation.html#STRICT"><code>Validation.LAX</code></a>.
         This attribute name is available as the constant <a class="bodylink"
            href="../javadoc/net/sf/saxon/lib/FeatureKeys.html#SCHEMA_VALIDATION"><code>FeatureKeys.SCHEMA_VALIDATION</code></a>.</p>
      <p>This option switches validation on for all source documents used by any transformation under the control of this
<code>TransformerFactory</code>. If you want finer control, so that some documents are validated and others are not, you can
achieve this by using the <a class="bodylink" href="../javadoc/net/sf/saxon/lib/AugmentedSource.html"><code>AugmentedSource</code></a> object. An <code>AugmentedSource</code> is a wrapper around
a normal JAXP <code>Source</code> object, in which additional properties can be set: for example, a property to
request validation of the document. The <code>AugmentedSource</code> itself implements the JAXP <code>Source</code>
interface, so it can be used anywhere that an ordinary <code>Source</code> object can be used, notably as the
first argument to the <code>transform</code> method of the <code>Transformer</code>, and as the return value from
a user-written <code>URIResolver</code>.</p>
      <p>If the <a class="bodylink" href="../javadoc/com/saxonica/ptree/PTreeURIResolver.html"><code>PTreeURIResolver</code></a> is used, it is also possible to control validation for each source document
by means of query parameters in the document URI. For example, <code>document('source.xml?val=strict')</code> requests
the loading of the file <code>source.xml</code> with strict validation.</p>
      <p>The attribute <a class="bodylink"
            href="../javadoc/net/sf/saxon/lib/FeatureKeys.html#VALIDATION_WARNINGS"><code>FeatureKeys.VALIDATION_WARNINGS</code></a> has the same effect as the <code>-vw</code>
option on the command line: validation errors encountered when processing the final result tree are
reported to the <code>ErrorListener</code> as warnings, not as fatal errors.</p>
      <p>Schemas can be loaded using either of the techniques used with the command-line interface: that is, by specifying
them in the <code>xsl:import-schema</code> directive in the stylesheet, or by including them in an <code>xsi:schemaLocation</code>
attribute in a source document. In addition, they can be loaded using the <code>addSchema()</code> method on the
<a class="bodylink"
            href="../javadoc/com/saxonica/config/SchemaAwareTransformerFactory.html"><code>SchemaAwareTransformerFactory</code></a> class.</p>
      <p>All schemas that are loaded are cached as part of the <code>TransformerFactory</code> (or more specifically, as
part of the <a class="bodylink" href="../javadoc/net/sf/saxon/Configuration.html"><code>Configuration</code></a> object owned by the <code>TransformerFactory</code>). This is true whether the
schema is loaded explicitly using the Java API, whether it is loaded as a result of <code>xsl:import-schema</code>,
or whether it is referenced in an <code>xsi:schemaLocation</code> attribute in a source document. There can only
be one schema document loaded for each namespace: any further attempts to load a schema for a given target namespace
will return the existing loaded schema, rather than loading a new one. Note in particular that this means there
can only be one loaded no-namespace schema document. If you want to force loading of a different schema document
for an existing namespace, the only way to do it is to create a new <code>TransformerFactory</code>.</p>
      <p>If you are validating the result tree, and you want your application to have access to the type annotations
in the validated tree, then you should specify as the result of the transformation either a user-written 
<code>Receiver</code>, or a <code>DOMResult</code> that wraps a Saxon <code>DocumentInfo</code> object. Note that
type annotations are supported only with the TinyTree implementation.</p>
      <table width="100%">
         <tr>
            <td>
               <p align="right"><a class="nav" href="saquerycmd.xml">Next</a></p>
            </td>
         </tr>
      </table>
   </body>
</html>