http://xml.apache.org/http://www.apache.org/http://www.w3.org/

Overview

Downloads
Getting Started

FAQs

Sample Apps
Command Line
Usage Patterns

C++ API

Extensions

Release Notes

Bug reporting

Samples to help you get started
 

Each of the subdirectories in the Xalan-C++ samples directory contains the source files for a sample application. In the Windows32 distribution, the executables for all the samples are in the build subdirectory, which should be on the system path. If you are using the Linux distribution, you must build the sample application executables yourself. Of course you can also consult the sample application source files for useful information about how to perform basic operations.

With most of the samples, you can use the following procedure:

  1. Go to the samples subdirectory containing the sample (use the DOS shell if you are running Windows)

  2. Run the sample from the command line (as indicated below)

  3. Examine the application source files. You may also want to modify the source files. Remember that if you modify a .cpp file, you must rebuild the executable and place it on the path before you can run the modified application.

SimpleTransform
 

What it does: The SimpleTransform class uses the foo.xsl stylesheet to transform foo.xml, and writes the output to foo.out.

You can run it from the SimpleTransform subdirectory with

SimpleTransform

See also: Basic procedures for performing XSL transformations.


UseStylesheetParam
 

What it does: Set a stylesheet parameter that the stylesheet uses during the transformation.

You can run it from the UseStylesheetParam subdirectory with

UseStylesheetParam key expression

where key is the parameter key (or name) and expression is a string expression enclosed in single quotes.

The example uses a stylesheet (foo.xsl) with a parameter named param1. The stylesheet accepts any string expression. Enclose the string expression in single quotes (so it is interpreted as an expression); if it includes more than a single word, enclose the resulting string in double quotes so the executable interprets it as a single argument. For example:

UseStylesheetParam param1 "'hello out there'"

See also: Setting stylesheet parameters.


TraceListen
 

What it does: Trace events during a transformation; the transformation uses birds.xsl to transform birds.xml and writes the output to birds.out.

You can run it from the TraceListen subdirectory with

TraceListen traceFlags

where traceFlags is one or more of the following:

  -TT (Trace the templates as they are being called)

  -TG (Trace each result tree generation event)

  -TS (Trace each selection event)

  -TTC (Trace the template children as they are being processed)

These flags are also available in the command-line utility (TestXSLT).

The core of this example is the following fragment:

// Set up a diagnostic writer to be used by the TraceListener...
XercesStdTextOutputStream  theStdErr(std::cerr);
XercesDOMPrintWriter       diagnosticsWriter(theStdErr);

// Set up the TraceListener...
// traceTemplates, traceTemplateChildren, traceGenerationEvent,
// and TraceSelectionEvent are booleans set by the command line.
auto_ptr<TraceListener> theTraceListener;
theTraceListener = auto_ptr<TraceListener>(new TraceListenerDefault(
        diagnosticsWriter,
        traceTemplates,
        traceTemplateChildren,
        traceGenerationEvent,
        traceSelectionEvent));

// Add the TraceListener to the XSLT processor...
theProcessor.setTraceSelects(traceSelectionEvent);
theProcessor.addTraceListener(theTraceListener.get());

// Perform the transformation
....

CompileStylesheet
 

What it does: Use a compiled stylesheet to perform a series of transformations.

You can run it from the CompileStylesheet subdirectory with

CompileStylesheet

See also: Compiling stylesheets.


ThreadSafe (Windows32 Only)
 

What it does: multiple threads use a single compiled stylesheet (StylesheetRoot) and DOM source tree (XalanNode) to perform transformations concurrently. The application tracks the progress of the threads in messages to the screen, and each thread writes its own output file. Imagine a server application responding to multiple clients who happen to request the same transformation.

NoteThis sample uses Windows libraries, but could readily be adapted to run under Linux and in other environments. It could also be adapted to perform a variety of transformations, each with its own XML input.

You can run it from the ThreadSafe subdirectory with

ThreadSafe

See also: Compiling stylesheets.


XPathWrapper
 

This sample uses TestDriver, an executable, and two classes: XPathWrapper and XPathWrapperImp.

What it does: TestDriver passes XPathWrapper an XML file name, a context node location path, and an XPath expression. XPathWrapper in turn passes these arguments to the XPathWrapperImpl evaluate() method, which executes the XPath expression from specified context node in the XML document and returns the nodes it finds (if any).

NoteYou can use this sample as an aid when you want to find out what a given XPath expression returns from a given context node in an XML file.

Run this sample from the XPathWrapper subdirectory with

TestDriver XMLFile ContextNode XPathExpression

where XMLFile is an XML source file, ContextNode is the location path to the context node, and XPathExpression is an XPath expression to apply to that context node. The XPathWrapper subdirectory contains an XML file named xml.foo (part of it appears below).

<?xml version="1.0"?>
<doc>
  <name first="David" last="Marston"/>
  <name first="David" last="Bertoni"/>
  ...
  <name first="Paul" last="Dick"/>
</doc>

You can try command lines like

TestDriver foo.xml /doc name/@last

and

TestDriver foo.xml //name[position()="4"]./@first

See also: Working with XPath expressions.


ExternalFunctions
 

What it does: implement, install, and illustrate the usage of three extension functions. The functions return a square root, a cube, and a string with the current date and time. The sample stylesheet (foo.xsl) gets the area of a cube and units of measurement from an XML document (foo.xml), computes the length of each side of a cube and the volume of the cube, and enters the date and time of the transformation. The output appears in foo.out.

Run this sample from the ExternalFunctions subdirectory with

ExternalFunctions

See also: Extension Functions.



Copyright © 2000 The Apache Software Foundation. All Rights Reserved.