Oracle9i XML Developer's Kits Guide - XDK Release 2 (9.2) Part Number A96621-01 |
|
This chapter contains the following sections:
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
.
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.
See the following:
See Also:
|
Figure 14-1 shows the XSLT for C functionality.
xmlparse()
:
xmlinit()
initializes the XSLT processing. xmlinit()
initializes the xslprocess()
result.xslprocess()o
ptionally 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.xmlterm()
for the XML document, stylesheet, and final result.XML Parser for C's XSLT functionality is illustrated with the following examples:
XSLT for C can be invoked in two ways:
The XSLT for C can be called as an executable by invoking bin/xml
Table 14-1 lists the 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 |
$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.
Change directories to the sample directory and read the README file. This will explain how to build the sample programs according to your platform.
Table 14-3 lists the programs built by the sample files in the sample directory.
Built Program | Description |
---|---|
XSLSample <xmlfile> <xsl ss> |
Sample usage of XSL processor. It takes two filenames as input, the XML file and XSL stylesheet |
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>
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; }
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>
|
Copyright © 2001, 2002 Oracle Corporation. All Rights Reserved. |
|