Setting Stylesheet Parameters

An XSL stylesheet can include parameters that are set at run time before a
transformation takes place.  Traditionally, a top-level parameter value is
of text string type.  The Xalan library now supports three types of
top-level parameters that can be set.  One is a text string parameter. 
Another is a number parameter of floating point type double.  The third is
a nodeset (XalanNode *) parameter, usually implemented as a parsed
document.

Any XObject that is created outside of the transformation can be
associated with a top-level parameter.  The XalanTransformer has an
XObject factory whereby top-level parameters can be owned by the
XalanTransformer object.

To set a stylesheet parameter, use the XalanTransformer
setStylesheetParam() method. The setStylesheetParam() method takes two
arguments: the parameter name and the value.  The value can be a string
type, a number double type, an XalanNode pointer to a nodeset or parsed
document, or any XObjectPtr returned from an XObject factory.

Top level parameters are sticky.  Once set to an instance of an
XalanTransformer object, they can be used for multiple transformations. 
The XalanTransformer reset() method prepares a transformer for a new
transformation.  Use the clearStylesheetParams() method to release the
top-level stylesheet parameters.

The Xalan comman line utility currently supports only a text string value
for a top-level stylesheet parameter.  The single quotes are required to
identify a text string value.

Xalan -p param1 "'string expression'"foo.xml foo.xsl

If the string expression includes spaces or other characters that the
shell intercepts, first enclose the string in single quotes so Xalan-C++
interprets it as a string expression, and then enclose the resulting
string in double quotes so the shell interprets it as a single argument.

The UseStylesheetParam sample application supports all three types of
top-level stylesheet parameters.

The 'C' language interface XalanCAPI also supports the three types of
top-level parameters.  The sample program TestCAPIparms.c shows how to use
top-level parameters with 'C' language programs.

[note] The Xalan command line utility should be revised to accommodate the
number and nodeset types of top-level stylesheet parameters. Only text
string values are currently supported.

Top-level stylesheet parameters of nodeset type (XalanNode *) are useful
for the merging of multiple XML documents.

[The Current Subversion: XALAN-C for 1.11]



Reply via email to