[All Packages]  [Previous]

XSLT API

A software module called an XSL processor is used to read XML documents and transform them into other XML documents with different styles.

The C implementation of the XSL processor follows the XSL Transformations standard (version 1.0, November 16, 1999) and implements the required behavior of an XSL processor as specified in the XSLT specification.


Calling Sequence

Typical calling sequence using xmlparse: Typical calling sequence using xmlparsexsl:

Data Types Index

oratext String pointer used for all data encodings, cast as needed; for UTF-16, to (ub2 *)
xmlctx Top-level XML context
xmlsaxcb SAX callback structure (SAX only)
xmlnode Document node
xmlstream Stream based output
xslctx Top-level XSL context
xsloutputmethod Output method for XSL processing
xpnset XPath node set
xpnsetele XPath node set element
xpobj XPath object
xpobjtyp XPath object type
ub4 32-bit (or larger) unsigned integer
uword Native unsigned integer

Function Index


XSLT

xslgetbaseuri Get baseURI associated with the XSLT context.
xslgetoutputdomctx Get result XML context.
xslgetoutputsax Get the output SAX object.
xslgetoutputstream Get the output XML stream.
xslgetresultdocfrag Get the resultant doc fragment (after xslprocessxml).
xslgettextparam Get a toplevel parameter/variable.
xslgetxslctx Get the XML context for the input XSL stylesheet.
xslinit Creates and initializes XSLT context.
xslprocess Processes XSL Stylesheet with XML document source.
xslprocessex Processes XSL Stylesheet with XML document source, extended.
xslprocessxml Do XSLT processing on a given input XML tree.
xslprocessdocfrag Do XSLT processing on a given input XML fragment.
xslresetallparams Resets all the top level parameters added.
xslsetoutputdomctx Set XML context for the output DOM tree.
xslsetoutputencoding Set XSLT output encoding.
xslsetoutputmethod Set XSLT output method.
xslsetoutputsax Set the XSLT output SAX callback object.
xslsetoutputsaxctx Set the XSLT output SAX context.
xslsetoutputstream Set the XSLT output stream callback object.
xslsettextparam Set a toplevel parameter.
xslterm Terminates an XSLT context.

XPath

xpevalxpathexpr Evaluates XPath expression
xpfreexpathctx Frees XPath context
xpgetbooleanval Returns value of XPath expression
xpgetfirstnsetelem Returns value of XPath expression
xpgetnextnsetelem Returns value of XPath expression
xpgetnsetelemnode Returns value of XPath expression
xpgetnsetval Returns value of XPath expression
xpgetnumval Returns value of XPath expression
xpgetrtfragval Returns value of XPath expression
xpgetstrval Returns value of XPath expression
xpgetxpobjtyp Returns value of XPath expression
xpmakexpathctx Creates an XPath contex.
xpparsexpathexpr Parses an XPath expression

Data Structures and Types


oratext

xmlctx

xmlnode

xmlstream

xmlsaxcb

xslctx

xsloutputmethod

xpobj

Note: The contents of xpobj are private and must not be accessed by users.

xpobjtyp

xpnset

Note: The contents of xpnset are private and must not be accessed by users.

xpnsetele

Note: The contents of xpnsetele are private and must not be accessed by users.

ub4

uword


Functions


xslprocess, xslprocessex

Purpose

Process an XSL Stylesheet with an XML document source. User can specify a list of toplevel parameters (xslprocessex) to be set before parsing begins.

Syntax
uword xslprocess   (xmlctx *docctx, xmlctx *xslctx, xmlctx *resctx, 
                    xmlnode **result);
uword xslprocessex (xmlctx *docctx, xmlctx *sctx, xmlctx *resctx,
                    size_t nparams, oratext *params[], oratext *vals[],
                    oratext *baseuri, xmlnode **result);

Parameters

docctx   (IN/OUT) - The XML document context
xslctx   (IN)     - The XSL stylesheet context
resctx   (IN)     - The result document fragment context
result   (IN/OUT) - The result document fragment node
nparams  (IN)     - Number of (params,vals) pairs to be passed
params   (IN)     - Array of name of pars (must be nparams in count)
vals     (IN)     - Array of value of pars (must be nparams in count)
baseuri  (IN)     - String giving the base uri for style sheet
Returns

LPXERR_OK on success, otherwise returns LPXERR_FAIL.  

xslprocessxml, xslprocessdocfrag

Purpose

Processes an XSL Stylesheet with an XML document source.

Syntax
uword xslprocessxml        (xslctx *xslSSctx, xmlctx *docctx, 
                            boolean normalize, ub4 resvd);
uword xslprocessxmldocfrag (xslctx *xslSSctx, xmlctx *docctx, 
                            xmlnode *docFrag,
                            boolean normalize, ub4 resvd);

Parameters

docctx   (IN/OUT) - The XML document context
xslSSctx (IN)     - The XSL processing context 
docFrag  (IN)     - The input document fragment node
normalize(IN)     - If TRUE then noramlize the input DOM tree.
resvd    (--)     - Reserved. Should be set to NULL.
Returns

LPXERR_OK on success, otherwise returns LPXERR_FAIL.  
Notes

Those XSLT API are supposed to be used after the user:
 (1) has created the XSLT processing context using xslinit, 
 (2) has set the base URI using xslinit, 
 (3) has set all the top level parameters using xslsettextparam,
 (4) has selected an output method using xslsetoutput.
The functions will process the given XML file (specified by docctx) 
according to the XSL stylesheet, parameters, and output method.
This call returns one of the following depending on the output scheme which 
the user might have selected:
  Stream based output: The output text has been redirected
                       using the stream callbacks.
  SAX based output:    User should have already got all 
                       the SAX events sent by XSLT.
  DOM based output:    User can make a call to the xslgetresultdocfrag
                       function to access the final Document Fragment
                       created in context of the resctx set by a call 
                       to xslsetoutputdomctx.

xslinit

Purpose

Creates and initializes an XSL context.

Syntax
xslctx* xslinit (uword *err, xmlctx *xsctx, 
                 const oratext *baseURI, ub4 resvd);

Parameters

err    (OUT) - LPXERR_OK on success, otherwise error code.
xslctx (IN)  - The XML context for the input stylesheet
baseURI(IN)  - The base URI for processing include and import statements
rsvd   (--)  - reserved for future usage, presently should be set NULL
Returns

The pointer to the XSL context object if successful, otherwise NULL.  

xslgetbaseuri

Purpose

Get baseURI associated with xsl context.

Syntax
const oratext* xslgetbaseuri (xslctx *xslSSctx);

Parameters

xslSSctx (IN) -  the XSL processing context to be inquired upon
Returns

The pointer to the base URI if successful, otherwise NULL.  

xslgetoutputdomctx

Purpose

Get output DOM associated with the XSL context.

Syntax
xmlctx* xslgetoutputdomctx (xslctx *xslSSctx);

Parameters

xslSSctx (IN) -  the XSL processing context to be inquired upon
Returns

The pointer to the output DOM context object if successful, otherwise NULL.  

xslgetoutputsax

Purpose

Get SAX object associated with the XSL context.

Syntax
xmlsaxcb* xslgetoutputsax (xslctx *xslSSctx);

Parameters

xslSSctx (IN) -  the XSL processing context to be inquired upon
Returns

The pointer to the output SAX object if successful, otherwise NULL.  

xslgetoutputstream

Purpose

Get output stream associated with the XSL context.

Syntax
xmlstream* xslgetoutputstream (xslctx *xslSSctx);

Parameters

xslSSctx (IN) -  the XSL processing context to be inquired upon
Returns

The pointer to the output stream object if successful, otherwise NULL.  

xslgetresultdocfrag

Purpose

Get resultant doc fragment associated with the XSL context.

Syntax
xmlnode* xslgetresultdocfrag (xslctx *xslSSctx);

Parameters

xslSSctx (IN) -  the XSL processing context to be inquired upon
Returns

The pointer to the document fragment node if successful, otherwise NULL.  

xslgetxslctx

Purpose

Get XML context for xsl stylesheet associated with xsl context.

Syntax
xmlctx* xslgetxslctx (xslctx *xslSSctx);

Parameters

xslSSctx (IN) -  the XSL processing context to be inquired upon
Returns

The pointer to the XML context object of the XSL stylesheet if successful,

otherwise NULL.


xslsettextparam

Purpose

Set a toplevel parameter(variable)

Syntax
uword xslsettextparam (xslctx *xslSSctx, const oratext *param_name, 
                        const oratext *param_value);

Parameters

xslSSctx   (IN) - The XSL processing context 
param_name (IN) - The name of parameter(variable) whose value is to be set.
param_val  (IN) - The parameter value
Returns

LPXERR_OK on success, otherwise returns LPXERR_FAIL.  

xslgettextparam

Purpose

Returns a top level parameter(variable) value

Syntax
const oratext *xslgettextparam (xslctx *xslSSctx, const oratext *param_name);

Parameters

xslSSctx   (IN) - The XSL processing context 
param_name (IN) - The name of parameter(variable) whose value is to be set.
Returns

The pointer to the variable/parameter value if successful, otherwise NULL.  

xslsetoutputdomctx

Purpose

Set Set XML context to store processing result (as DOM).

Syntax
uword xslsetoutputdomctx (xslctx *xslSSctx, xmlctx *resctx);

Parameters

xslSSctx (IN) - The XSL processing context 
resctx   (IN) - The XML context object in which the output document 
                fragment will be stored. This pointer must remain valid 
                through out the duration when this context is used to
                generate the processing event during subsequent 
                processing of XML trees.
Returns

LPXERR_OK on success, otherwise returns LPXERR_FAIL.  
Notes

A call to xslsetoutputdomctx  overrides any previous output
method set using any previous calls to xslsetoutputdomctx or 
xslsetoutputstream or xslsetoutputsax. Any subsequent 
processing of the XML input will be stored in form of a Document 
Fragment in the xmlctx specified by resctx. xslgetoutputdomctx  
can be used to retrieve the presently set resctx. If no DOM context 
is set or a call to xslsetoutputdomctx  has been overridden 
by a subsequent call to xslsetoutputstream or xslsetoutputsax,
then xslgetoutputdomctx will return a NULL context indicating 
that the present output mode is not a DOM output mode.

xslsetoutputencoding

Purpose

Set XSLT output encoding. Overrides the XSL Stylesheet settings.

Syntax
uword xslsetoutputencoding (xslctx *xslSSctx, oratext* outcoding);

Parameters

xslSSctx  (IN) - The XSL processing context 
outcoding (IN) - Encoding name for the output encoding.
Returns

LPXERR_OK on success, otherwise returns LPXERR_BAD_ENCODING.  
Notes

This call is used to set an output method equivalent to XSL 
processing directive xsl:output encoding = ".....".
If the xsl stylesheet contains one or more similar statements,
then this function will override the effect of any previously
present statements in XSL stylesheet.  

xslsetoutputmethod

Purpose

Set XSLT output method. Overrides the XSL Stylesheet settings.

Syntax
uword xslsetoutputmethod (xslctx *xslSSctx, xsloutputmethod method, ub4 resvd);

Parameters

xslSSctx (IN) - The XSL processing context. 
method   (IN) - Output method to be selected.
resvd    (--) - Reserved for future, user must set it to NULL.
Returns

LPXERR_OK on success, otherwise returns LPXERR_FAIL.  
Notes

This call is used to set an output method equivalent to XSL 
processing directive xsl:output method = "text/xml/html".
If the xsl stylesheet contains one or more similar statements,
then this function will override the effect of any previously
present statements in XSL stylesheet.

xslsetoutputsax, xslsetoutputsaxctx

Purpose

Set the SAX based events to be generated for the output.

Syntax
uword xslsetoutputsax    (xslctx *xslSSctx, xmlsaxcb *s);
uword xslsetoutputsaxctx (xslctx *xslSSctx, void *saxctx);

Parameters

xslSSctx (IN) - The XSL processing context. 
s        (IN) - The SAX callbacks  to be used to generate the SAX events.
saxctx   (IN) - The SAX context.
Returns

LPXERR_OK on success, otherwise returns LPXERR_FAIL.  
Notes

The user can make a call to xslsetoutputsaxctx to set the SAX context to be
used by the SAX callbacks. If none is set, then a NULL will be passed to 
the SAX callbacks as SAX context. Also note that just setting the 
callbacks is sufficient to invoke the SAX callbacks.

xslsetoutputstream

Purpose

Set the stream object specifying callbacks to generate the text stream based output.

Syntax
uword xslsetoutputstream (xslctx *xslSSctx, xmlstream * stream);

Parameters

xslSSctx (IN) - The XSL processing context. 
stream   (IN) - The stream structure giving the callbacks to be used.
Returns

LPXERR_OK on success, otherwise returns LPXERR_FAIL.  

xslresetallparams

Purpose

Reset all the top level parameters added.

Syntax
uword xslresetallparams (xslctx *xslSSctx);

Parameters

xslSSctx   (IN) - The XSL processing context 
Returns

LPXERR_OK on success, otherwise returns LPXERR_FAIL.  

xslterm

Purpose

Terminates an XSLT context object.

Syntax
uword xslterm (xslctx *xslSSctx);

Parameters

xslSSctx (IN) - The XSL processing context. 
Returns

LPXERR_OK on success, otherwise returns LPXERR_FAIL.  

xpmakexpathctx

Purpose

Creates an XPath context.

Syntax
xpctx *xpmakexpathctx (xmlctx *ctx, xmlnode *xslnode, 
                       xmlnode* xml_node, oratext* baseURI, 
                       size_t nctxels, xmlnode ** ctxnodes);

Parameters

sctx     (IN) - XSL context. Could be NULL. 
xslnode  (IN) - The XSL node to be used for namespace expansion. 
               Could be set to NULL.
xmlnode  (IN) - The context node. Set to NULL for parsing.
baseURI  (IN) - The base URI for parsing.
nctxels  (IN) - The number of nodes in the current node set. 
ctxnodes (IN) - The current node set.
Returns

An XPath context object. This call never fails.  

xpfreexpathctx

Purpose

Frees an XPath context.

Syntax
void xpfreexpathctx (xpctx *xctx);

Parameters

xctx (IN) - The XPath context to be freed. 

xpparsexpathexpr

Purpose

Parses an XPath expression.

Syntax
xpexpr *xpparsexpathexpr (xpctx *xctx, oratext *expr, sword *err);

Parameters

xctx (IN/OUT) - The xpath context
expr (IN)     - The expression in the form of a string.
err  (OUT)    - The error code.
Returns

On success, returns the expression tree. On failure, returns NULL.  

xpevalxpathexpr

Purpose

Evaluates an XPath expression.

Syntax
xpobj *xpevalxpathexpr (xpctx *xctx, xpexpr *exprtree, sword *err);

Parameters

xctx     (IN/OUT) - The xpath context
exprtree (IN)     - The expression in the form of a tree.
err      (OUT)    - The error code.
Returns

On success, returns the result object. On failure, returns NULL.  
Notes

The type of the result object is one of the following:

XPOBJTYP_BOOL XPOBJTYP_NUM XPOBJTYP_STR XPOBJTYP_NSET XPOBJTYP_RTFRAG

The object type can be obtained using xpgetxpobjtyp.


xpgetbooleanval

xpgetxpobjtyp

xpgetnumval

xpgetstrval

xpgetnsetval

xpgetfirstnsetelem

xpgetnextnsetelem

xpgetnsetelemnode

xpgetrtfragval

Purpose

Get values of evaluated xpath expression result.

Syntax
xpobjtyp   xpgetxpobjtyp      (xpobj *xobj);
boolean    xpgetbooleanval    (xpobj *xobj);
double     xpgetnumval        (xpobj *xobj);
oratext*   xpgetstrval        (xpobj *xobj);
xpnset*    xpgetnsetval       (xpobj *xobj);
xmlnode*   xpgetrtfragval     (xpobj *xobj);
xpnsetele* xpgetfirstnsetelem (xpnset *nset);
xpnsetele* xpgetnextnsetelem  (xpnsetele *nsetele);
xmlnode*   xpgetnsetelemnode  (xpnsetele *nsetele);

Parameters

xobj    (IN) - The expression object
nset    (IN) - The node set.
nsetele (IN) - The node set element.
Returns

On success, returns the expression value. On failure, returns NULL.  
Example:

...
xctx = xpmakexpathctx(...);
...
exprtree = xpparsexpathexpr(xctx, ...);
...
xobj = xpevalxpathexpr(xctx, exprtree, ...);
...
switch (xpgetxpobjtyp(xobj))
{
case XPOBJTYP_BOOL:
    bval = xpgetbooleanval(xobj);  /* bval is of type boolean */
      ... Use bval;
    break;
case XPOBJTYP_NUM:
    nval = xpgetnumval(xobj);      /* nval is of type double */
      ... Use nval;
    break;
case XPOBJTYP_STR:
    strval = xpgetstrval(xobj);    /* strval is of type oratext */
      ... Use strval;
    break;
case XPOBJTYP_NSET:
    nsetval = xpgetnsetval(xobj); 
      ... Use nset as follws: nsetele is of type xpnsetele*
    for (nsetele = xpgetfirstnsetelem(nsetval);
         nsetelem; 
         nsetelem = xpgetnextnsetelem(nsetval))
    {
         node = xpgetnsetelemnode(nsetele); 
           ... Use node 
    }
    break;
case XPOBJTYP_RTFRAG:
    node = xpgetrtfragval(xobj);    /* node is of type xmlnode */
    break;
}