Skip Headers

Oracle9i XML Developer's Kits Guide - XDK
Release 2 (9.2)

Part Number A96621-01
Go To Documentation Library
Home
Go To Product List
Book List
Go To Table Of Contents
Contents
Go To Index
Index

Master Index

Feedback

Go to previous page Go to next page

14
XSLT Processor for C

This chapter contains the following sections:

Accessing XSLT for C

XSLT for C is provided with Oracle9i and Oracle9i Application Server. It is also available for download from the OTN site: http://otn.oracle.com/tech/xml

It is located in $ORACLE_HOME/xdk/c/parser.

XSLT for C Features

readme.html in the root directory of the software archive contains release specific information including bug fixes and API additions.

You can post questions, comments, or bug reports to the XML Discussion Forum at http://otn.oracle.com/tech/xml.

Specifications

See the following:

See Also:

XML XSLT for C (DOM Interface) Usage

Figure 14-1 shows the XSLT for C functionality.

  1. There are two inputs to xmlparse():
    • The stylesheet to be applied to the XML document
    • XML document
  2. xmlinit() initializes the XSLT processing. xmlinit() initializes the xslprocess() result.
  3. xslprocess()optionally calls other functions, such as print functions. You can see the list of available functions either on OTN or in the Oracle9i XML API Reference - XDK and Oracle XML DB.
  4. The resultant document (XML, HTML, VML, and so on) is typically sent to an application for further processing.
  5. The application terminates the XSLT process by declaring xmlterm() for the XML document, stylesheet, and final result.

XML Parser for C's XSLT functionality is illustrated with the following examples:

Figure 14-1 XSLT for C (DOM Interface) Usage

Text description of adxml056.gif follows
Text description of the illustration adxml056.gif


Invoking XSLT for C

XSLT for C can be invoked in two ways:

Command Line Usage

The XSLT for C can be called as an executable by invoking bin/xml

Table 14-1 lists the command line options.

Table 14-1 XML Parser for C: Command Line Options
Option Description

-e encoding

Specify input file encoding

-h

Help - show this usage help

-v

Version - display parser version then exit

-w

Whitespace - preserve all whitespace

-s

Stylesheet

Using the Sample Files Included with the Software

$ORACLE_HOME/xdk/c/parser/sample directory contains several XML applications to illustrate how to use the XSLT for C.

Table 14-2 lists the sample files in sample/ directory.

Table 14-2 XSLT for C sample/ Files
sample/ File Name Description

XSLSample.c

Source for XSLSample program

XSLSample.std

Expected output from XSLSample

class.xml

XML file that may be used with XSLSample

iden.xsl

Stylesheet that may be used with XSLSample

cleo.xml

XML version of Shakespeare's play

--

Running the XSLT for C Sample Programs

Building the Sample Programs

Change directories to the sample directory and read the README file. This will explain how to build the sample programs according to your platform.

Sample Programs

Table 14-3 lists the programs built by the sample files in the sample directory.

Table 14-3 XSLT for C: Sample Built Programs in sample/ 
Built Program Description

XSLSample <xmlfile> <xsl ss>

Sample usage of XSL processor. It takes two filenames as input, the XML file and XSL stylesheet

XSLT for C Example1: XSL -- iden.xsl

This example stylesheet can be used to input XSLSample.c.

<?xml version="1.0"?> 
<!-- Identity transformation -->
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
                
  <xsl:template match="*|@*|comment()|processing-instruction()|text()">
      <xsl:copy>
          <xsl:apply-templates 
select="*|@*|comment()|processing-instruction()|text()"/>
      </xsl:copy>
  </xsl:template>
     
</xsl:stylesheet>

XSLT for C Example 2: C -- XSLSample.c

This example contains C source code for XSLSample.c.

/* Copyright (c) Oracle Corporation 1999. All Rights Reserved. */

/*
   NAME
     XSLSample.c - Sample function for XSL 
   DESCRIPTION
     Sample usage of C XSL Processor
*/

#include <stdio.h>
#ifndef ORATYPES
# include <oratypes.h>
#endif

#ifndef ORAXML_ORACLE
# include <oraxml.h>
#endif

int main(int argc, char *argv[])
{
    xmlctx     *xctx, *xslctx, *resctx;
    xmlnode    *result;
    uword       ecode;
    /* Check for correct usage */
    if (argc < 3)
        {
        puts("Usage is XSLSample <xmlfile> <xslfile>\n");
        return 1;
        }

    /* Parse the XML document */
    if (!(xctx = xmlinit(&ecode, (const oratext *) 0,
                        (void (*)(void *, const oratext *, uword)) 0,
                        (void *) 0, (const xmlsaxcb *) 0, (void *) 0,
                        (const xmlmemcb *) 0, (void *) 0,
                        (const oratext *) 0)))
    {
        printf("Failed to initialze XML parser, error %u\n", (unsigned) ecode);
        return 1;
    }

    printf("Parsing '%s' ...\n", argv[1]);
    if (ecode = xmlparse(xctx, (oratext *)argv[1], (oratext *) 0,
                        XML_FLAG_VALIDATE | XML_FLAG_DISCARD_WHITESPACE))
    {
        printf("Parse failed, error %u\n", (unsigned) ecode);
        return 1;
    }

    /* Parse the XSL document */
    if (!(xslctx = xmlinit(&ecode, (const oratext *) 0,
                        (void (*)(void *, const oratext *, uword)) 0,
                        (void *) 0, (const xmlsaxcb *) 0, (void *) 0,
                        (const xmlmemcb *) 0, (void *) 0,
                        (const oratext *) 0)))
    {
        printf("Failed to initialze XML parser, error %u\n", (unsigned) ecode);
        return 1;
    }

    printf("Parsing '%s' ...\n", argv[2]);
    if (ecode = xmlparse(xslctx, (oratext *)argv[2], (oratext *) 0,
                        XML_FLAG_VALIDATE | XML_FLAG_DISCARD_WHITESPACE))
    {
        printf("Parse failed, error %u\n", (unsigned) ecode);
        return 1;
    }

    /* Initialize the result context */
    if (!(resctx = xmlinit(&ecode, (const oratext *) 0,
                        (void (*)(void *, const oratext *, uword)) 0,
                        (void *) 0, (const xmlsaxcb *) 0, (void *) 0,
                        (const xmlmemcb *) 0, (void *) 0,
                        (const oratext *) 0)))
    {
        printf("Failed to initialze XML parser, error %u\n", (unsigned) ecode);
        return 1;
    }

    /* XSL processing */
    printf("XSL Processing\n");
    if (ecode = xslprocess(xctx, xslctx, resctx, &result))
    {
        printf("Parse failed, error %u\n", (unsigned) ecode);
        return 1;
    }

    /* Print the result tree */
    printres(resctx, result);

    /* Call the terminate functions */
    (void)xmlterm(xctx);
    (void)xmlterm(xslctx);
    (void)xmlterm(resctx);

    return 0;
}

XSLT for C Example 3: C -- XSLSample.std

XSLSample.std shows the expected output from XSLSample.c.

Parsing 'class.xml' ...
Parsing 'iden.xsl' ...
XSL Processing
<root>
   <course>
      <Name>Calculus</Name>
      <Dept>Math</Dept>
      <Instructor>
         <Name>Jim Green</Name>
      </Instructor>
      <Student>
         <Name>Jack</Name>
         <Name>Mary</Name>
         <Name>Paul</Name>
      </Student>
   </course>
</root>


Go to previous page Go to next page
Oracle
Copyright © 2001, 2002 Oracle Corporation.

All Rights Reserved.
Go To Documentation Library
Home
Go To Product List
Book List
Go To Table Of Contents
Contents
Go To Index
Index

Master Index

Feedback