Exécution d'opérations de base avec XSLT

Vous pouvez utiliser les instances XSLTExecutable qui sont créées par la méthode XFactory.prepareXSLT pour exécuter des transformations XSLT.

Pourquoi et quand exécuter cette tâche

Vous pouvez communiquer des feuilles de style XSLT à la méthode XFactory.prepareXSLT à l'aide d'un objet JAXP Source. L'instance XSLTExecutable obtenue bénéficie d'unités d'exécution sécurisées et peut être réutilisée pour transformer plusieurs documents d'entrée.

Procédure

Exemple

L'exemple suivant illustre comment préparer puis exécuter une transformation interprétée.
// Create the factory
XFactory factory = XFactory.newInstance();

// Create a StreamSource for the stylesheet
StreamSource stylesheet = new StreamSource("simple.xsl");

// Create an XSLT executable for the stylesheet
XSLTExecutable executable = factory.prepareXSLT(stylesheet);

// Create the input source
Source input = new StreamSource("simple.xml");

// Create the result
Result result = new StreamResult(System.out);

// Execute the transformation
executable.execute(input, result);
L'exemple suivant illustre comment préparer puis exécuter une transformation compilée.
// Create the factory
XFactory factory = XFactory.newInstance();

// Create a StreamSource for the stylesheet
StreamSource stylesheet = new StreamSource("simple.xsl");

// Create a new static context
XStaticContext staticContext = factory.newStaticContext();

// Enable the compiler
staticContext.setUseCompiler(true);

// Create an XSLT executable for the stylesheet
XSLTExecutable executable = factory.prepareXSLT(stylesheet, staticContext);

// Create the input source
Source input = new StreamSource("simple.xml");

// Create the result
Result result = new StreamResult(System.out);

// Execute the transformation
executable.execute(input, result);
L'exemple suivant illustre comment créer une transformation d'identité.
// Create the factory
XFactory factory = XFactory.newInstance();
           
// Create the item factory
XItemFactory itemFactory = factory.getItemFactory();

// Create the input source
Source input = new StreamSource("simple.xml");
           
// Create the XItemView object from the input source
XItemView item = itemFactory.item(input);
           
// Create an XOutputParameters object
XOutputParameters params = factory.newOutputParameters();

// Set parameters
params.setMethod("xml");
params.setEncoding("UTF-8");
params.setIndent(true);
           
// Create the result
Result result = new StreamResult(System.out);
           
// Serialize to the result
item.exportItem(result, params);
L'exemple suivant illustre comment créer une transformation basée sur un schéma.
// Create the factory
XFactory factory = XFactory.newInstance();

// Enable validation
factory.setValidating(true);

// Create the schema source
StreamSource schema = new StreamSource("schema.xsd");

// Register the schema
factory.registerSchema(schema);

// Create the stylesheet source
StreamSource stylesheet = new StreamSource("schema.xsl");

// Create an XSLT executable for the stylesheet
XSLTExecutable executable = factory.prepareXSLT(stylesheet);

// Create the input source
StreamSource input = new StreamSource("schema.xml");

// Create the result
StreamResult result = new StreamResult(System.out);

// Execute the transformation
executable.execute(input, result);

Icône indiquant le type de rubrique Rubrique de tâche



Icône d'horodatage Dernière mise à jour: last_date
http://www14.software.ibm.com/webapp/wsbroker/redirect?version=cord&product=was-nd-mp&topic=txml_ops_xslt
Nom du fichier : txml_ops_xslt.html