TOM KAISER (GINGER ALLIANCE)
JUNE 17, 2001
THE HTML FORM OF THIS DESCRIPTION WAS COMPILED BY SABLOTRON FROM THE XML SOURCE SABLOT-0-60.XML.
THE MATERIAL IN THE FOLLOWING SECTIONS INCLUDES:
XSLT IS A LANGUAGE ALLOWING TO TRANSFORM GIVEN XML DATA (THE INPUT) ACCORDING TO A STYLESHEET. XSLT STYLESHEETS ARE THEMSELVES XML DOCUMENTS; THAT IS, ALL INSTRUCTIONS OF THE LANGUAGE ARE EXPRESSED IN THE FORM OF XML ELEMENTS. THE OUTPUT, I.E. THE RESULT OF THE PROCESSING, IS TYPICALLY A XML DOCUMENT AS WELL, ALTHOUGH THE SYNTACTIC REQUIREMENTS CAN BE RELAXED TO ALLOW THE CREATION OF A HTML DOCUMENT (ONE THAT CONTAINS UNCLOSED TAGS AND THE LIKE), OR EVEN PLAIN TEXT.
XSLT WAS DESIGNED BY THE WORLD WIDE WEB CONSORTIUM (W3C) AS A PART OF THE XSL STYLESHEET LANGUAGE, WHERE IT IS COMPLEMENTED BY A POWERFUL SET OF FORMATTING INSTRUCTIONS. THE MOST PRECISE INFORMATION ABOUT XSLT CAN BE FOUND IN THE W3C RECOMMENDATION [XSLT]. IN PARTICULAR, APPENDIX B OF THE RECOMMENDATION CONTAINS A HANDY SYNTAX TABLE. A GOOD TUTORIAL IS [XMLBIBLE14].
OTHER W3C RECOMMENDATIONS ONE OFTEN NEEDS TO CONSULT ARE [XML] (FOR THE DEFINITION OF THE XML LANGUAGE) AND [XPATH] (FOR DETAILS ON XPATH, THE LANGUAGE USED TO FORM EXPRESSIONS IN XSLT AND ELSEWHERE).
AN EXCELLENT SOURCE OF INFORMATION ABOUT XSLT (INDEED, ABOUT ANYTHING RELATED TO XML AND SGML) IS [COVER]; SEE ALSO [XSLINFO] AND [XMLORG].
SABLOTRON IS A XSLT PROCESSOR (THOUGH NOT QUITE CONFORMING YET..., SEE BELOW) WRITTEN IN C++. SINCE THE MACHINES WHERE IT IS MEANT TO RUN INCLUDE VARIOUS SMALL MOBILE CLIENTS, THE MAIN OBJECTIVES OF ITS DESIGN ARE THE FOLLOWING:
SABLOTRON IS A SINGLE SHARED LIBRARY
(SABLOT.DLL
OR LIBSABLOT.SO.0.60
). IT CAN
ALSO BE USED FROM THE COMMAND LINE VIA THE SIMPLE INTERFACE
CALLED SABCMD
. SEE HERE FOR
MORE INFORMATION.
THE ONLY SOFTWARE SABLOTRON RELIES ON IS EXPAT, THE XML PARSER BY JAMES CLARK. SEE BELOW FOR INFORMATION ON HOW TO GET EXPAT.
FOR INFORMATION ON THE AVAILABLE INTERFACES, E.G. FOR PYTHON, PERL AND PHP, SEE WWW.GINGERALL.COM.
SABLOTRON IS WRITTEN IN C++. THE SOURCE FILES COMPILE UNDER WIN32 (USING MS VISUAL C++ 6.0) AND ON SOLARIS AND LINUX (USING G++ 2.95.2) WITHOUT CHANGE.
THE SOURCE OR BINARY DISTRIBUTIONS OF SABLOTRON CAN BE DOWNLOADED FROM WWW.GINGERALL.COM. FOR INSTRUCTIONS ON HOW TO BUILD THE SOURCES (IF ANY), REFER TO THE ACCOMPANYING INSTALL FILE.
IF YOU HAVE ACCESS TO THE GINGER ALLIANCE CVS SERVER, YOU
CAN GET THE WORKING VERSION OF SABLOTRON IN THE CVS MODULE
GA
. THE ACCESS RIGHTS CAN BE OBTAINED ON
REQUEST FROM THE CVS ADMIN.
SINCE VERSION 0.50, SABLOTRON USES EXPAT 1.95.1, AVAILABLE FROM SOURCEFORGE.
SABLOTRON IS AN OPEN SOURCE PROJECT AND ALL VOLUNTEERS ARE MOST WELCOME! THE DOCUMENTATION OF THE SOURCES IS STILL SOMEWHAT SPARSE BUT WE WILL TRY TO IMPROVE IT. IF YOU FIND THE INVITATION TO WORK ON SABLOTRON WITH US INTERESTING, PLEASE CONTACT US. THERE IS ALSO A MAILING LIST AVAILABLE, SEE WWW.GINGERALL.COM.
THE INSTRUCTION SET SUPPORTED BY THIS VERSION OF SABLOTRON IS ALREADY SUFFICIENT FOR MANY TRANSFORMATION TASKS (E.G. THE TASK OF FORMATTING THIS DOCUMENT). ON THE OTHER HAND, A COMPARISON OF IT TO THE XSLT SPECIFICATION [XSLT] SHOWS THAT MUCH IS STILL TO BE DONE. THE PURPOSE OF THE FOLLOWING SECTIONS IS TO DESCRIBE THE VARYING DEGREE OF SUPPORT FOR THE ELEMENTS OF THE XSLT LANGUAGE.
IT MAY BE HELPFUL TO REFER TO THE SYNTAX TABLE IN APPENDIX B OF [XSLT]. THE INSTRUCTIONS/ATTRIBUTES THAT ARE NOT LISTED AS UNSUPPORTED SHOULD BE IMPLEMENTED. THE AUTHORS WILL APPRECIATE BEING TOLD ABOUT ANY OMISSIONS FOUND IN THE FOLLOWING DESCRIPTION.
FOR READABILITY, I SOMETIMES OMIT THE XSL:
PREFIX
FROM THE INSTRUCTION NAMES.
TEMPLATE, APPLY-TEMPLATES, CALL-TEMPLATE
FULLY IMPLEMENTED. XSL:SORT
IS SUPPORTED SINCE RELEASE 0.50.
VARIABLE, PARAM, WITH-PARAM
FULLY IMPLEMENTED. TOP-LEVEL VARIABLES AND PARAMETERS ARE READ IN THE DOCUMENT ORDER, SO NO FORWARD REFERENCES ARE RESOLVED. THIS IS A MINOR DEVIATION FROM THE SPEC.
ELEMENT, ATTRIBUTE, TEXT,
COMMENT, PROCESSING-INSTRUCTION, ATTRIBUTE-SET
XSL:ATTRIBUTE-SET
IS NOT IMPLEMENTED. FOR THE
REST, NAME
IS THE ONLY RECOGNIZED ATTRIBUTE (WHERE
APPLICABLE). LITERAL RESULT ELEMENTS WORK.
STYLESHEET, TRANSFORM, OUTPUT
FOR STYLESHEET
AND TRANSFORM
,
THE ONLY RECOGNIZED ATTRIBUTE IS
VERSION
. XSL:OUTPUT
SHOULD WORK
(SEE BELOW FOR NOTES ON THE ENCODING
ATTRIBUTE). HTML INDENTATION HAS BEEN ADDED IN 0.60.
VALUE-OF, COPY, COPY-OF
COPY-OF
AND VALUE-OF
ARE FULLY
IMPLEMENTED. COPY
IS IMPLEMENTED EXCEPT FOR THE
USE-ATTRIBUTE-SETS
ATTRIBUTE.
NAMESPACE-ALIAS
NAMESPACES SHOULD BE PROCESSED CORRECTLY. THE
NAMESPACE-ALIAS
INSTRUCTION IS NOW SUPPORTED
(PATCH BY MAJOR).
SORT
XSL:SORT
IS IMPLEMENTED SINCE 0.50. THERE ARE
MINOR LIMITATIONS:
LANG
ATTRIBUTE MAY ONLY
CONTAIN THE VALUES "EN"
OR "CZ"
.CASE-ORDER
CANNOT BE SPECIFIED.
STRIP-SPACE, PRESERVE-SPACE
ONLY THE DEFAULT WHITESPACE STRIPPING IS DONE. THAT IS,
ALL WHITESPACE-ONLY TEXT NODES IN ANY STYLESHEET, NOT APPEARING
INSIDE A XSL:TEXT
, ARE REMOVED. THE TWO
INSTRUCTIONS FOR WHITESPACE STRIPPING AND PRESERVATION ARE
UNSUPPORTED.
INCLUDE, IMPORT, APPLY-IMPORTS
ONLY XSL:INCLUDE
IS IMPLEMENTED. PROCESSING
INVOLVING MULTIPLE DOCUMENTS WORKS, BUT HAS TO GET MORE TESTING,
EG. WITH RESPECT TO GENERATE-ID()
.
THE OUTPUT MECHANISM IS MUCH CLOSER TO THE SPEC THAN IN THE VERSIONS PRIOR TO 0.4. THE FOLLOWING ISSUES REMAIN FOR THE HTML METHOD:
<SCRIPT>
AND
<STYLE>
ALMOST ALL FEATURES OF XPATH ARE FULLY IMPLEMENTED. THIS MEANS THERE SHOULD BE NO PROBLEMS WITH EXPRESSIONS OF ANY KIND.
ONE EXCEPTION RELATES TO AXES. THE FOLLOWING
AND
PRECEDING
AXES HAVEN'T BEEN IMPLEMENTED YET.
ANOTHER POSSIBLE EXCEPTION MAY BE NUMBERS; WE DID NOT YET DO A THOROUGH TEST OF ROUNDING, NANS, INFINITY, ETC.
ONLY A FEW FUNCTIONS FROM THE STANDARD FUNCTION LIBRARY REMAIN UNIMPLEMENTED:
ID()
,LANG()
(ACCEPTED BUT ALWAYS RETURNS TRUE),KEY()
,FORMAT-NUMBER()
,UNPARSED-ENTITY-URI()
.AS FOR THE FUCTIONS THAT ARE IMPLEMENTED, THE FOLLOWING IS A LIST OF DIFFERENCES FROM THE SPEC:
DOCUMENT()
ONLY ACCEPTS ONE ARGUMENT, ALWAYS
GETTING THE BASE URI FROM THE STYLESHEET URI.
STRING-LENGTH()
RETURNS THE BYTE LENGTH OF
THE UTF-8 REPRESENTATION OF THE STRING. THIS WILL TYPICALLY
DIFFER FROM THE ACTUAL LENGTH.
GENERATE-ID()
MIGHT FAIL TO GENERATE UNIQUE IDENTIFIERS
WHEN SEVERAL INPUT DOCUMENTS ARE PRESENT (GIVING THE SAME ID TO
NODES FROM DIFFERENT DOCUMENTS).
IT IS POSSIBLE FOR THE USER TO SUPPLY THE FOLLOWING HANDLERS TO SABLOTRON:
THE HANDLERS ARE SET USING SABLOTREGHANDLER()
FOR DETAILS CONCERNING THE INTERFACE OF THESE HANDLERS,
CONSULT THE HEADER FILES SABLOT.H
AND
SHANDLER.H
.
IN VERSION 0.52, THE ENCODING CONVERSION CAPABILITIES OF SABLOTRON HAVE BEEN MUCH EXTENDED. THE MOST IMPORTANT FACT IS THE FOLLOWING: IF YOU HAVE THE ICONV LIBRARY INSTALLED ON YOUR SYSTEM, YOU CAN USE ANY ENCODING IT SUPPORTS (THAT IS, ALMOST ANY ENCODING WHATSOEVER) FOR BOTH THE INPUT AND THE OUTPUT DOCUMENTS. ICONV IS AVAILABLE ON MOST SYSTEMS (IT IS A STANDARD PART OF GLIBC2, FOR INSTANCE). THERE ARE IMPLEMENTATIONS FOR WIN32 AS WELL.
IF ICONV IS NOT AVAILABLE, THE ENCODING MAY STILL BE SUPPORTED INTERNALLY BY SABLOTRON. AT PRESENT, THE LIST IS OF SUCH ENCODINGS IS RATHER SHORT: BESIDES UTF-8, THESE ARE UTF-16, ASCII, ISO-8859-1, ISO-8859-2 AND WINDOWS-1250 ON INPUT, NONE ON OUTPUT. HOWEVER, WE PLAN TO IMPLEMENT A HALF INDEPENDENT LIGHT-WEIGHT CONVERSION LIBRARY FOR USE ON SYSTEMS WITHOUT ICONV, EXTENDING THE SET OF INTERNALLY SUPPORTED ENCODINGS CONSIDERABLY.
LASTLY, THE USER HAS THE OPTION TO IMPLEMENT A CUSTOM
ENCODING CONVERSION HANDLER, WHICH WILL BE ASKED TO PERFORM ANY UNSUPPORTED
CONVERSION. SEE THE SHANDLER.H
HEADER FILE FOR
DETAILS.
THE DEFAULT INPUT AND OUTPUT ENCODING IS IN ALL CASES UTF-8.
IN ADDITION TO THE STANDARD OUTPUT METHODS (XML, HTML AND
TEXT), IT IS POSSIBLE TO OUTPUT XHTML. DOCUMENTS OUTPUT USING
THIS METHOD OBEY THE XHTML 1.0 RULES (IN PARTICULAR, ALL EMPTY
ELEMENTS ARE CLOSED). TO CHOOSE THE METHOD, USE
<XSL:OUTPUT METHOD='XHTML'>
. PLEASE NOTE
THAT THE NAME OF THIS METHOD WILL POSSIBLY BE CHANGED SINCE THE XSLT
SPEC REQUIRES ANY PROCESSOR-SPECIFIC METHODS TO HAVE QUALIFIED
NAMES, SAY SAB:XHTML
. ON THE OTHER HAND, THE NAME
XHTML
IS CONSIDERED IN THE XSLT 2.0 WORKING DRAFT.
SABLOTRON CAN HANDLE
TWO URI SCHEMES NATIVELY: 'FILE' AND 'ARG' (SEE
BELOW). MOREOVER, IT IS POSSIBLE TO USE THE FUNCTION
SABLOTREGSCHEMEHANDLER
TO REGISTER AN EXTERNAL SCHEME
HANDLER WHICH WILL RECEIVE REQUESTS IN ALL OTHER SCHEMES. SEE
THE DOCUMENTATION IN SABLOT.H
AND
SHANDLER.H
.
RELATIVE URI REFERENCES ARE RESOLVED IN CONFORMANCE TO RFC 2396. THE BASE URI IS WELL DEFINED WHEN THE RELATIVE REFERENCE APPEARS INSIDE A XML DOCUMENT; WHEN INVOKING SABCMD, THE BASE URI IS TAKEN TO CORRESPOND TO THE CURRENT WORKING DIRECTORY.
WHEN SPECIFYING FILENAMES, THE FOLLOWING RULES ARE IN EFFECT:
STDIN
AS FILE://STDIN
ETC.C:\DOC.XML
), IT IS NECESSARY TO SAY
FILE://C:/DOC.XML
.
SABLOTRON INTRODUCES AN URI SCHEME 'ARG:' WHICH ENABLES ONE TO USE STRINGS IN NAMED MEMORY BUFFERS. THE BUFFER NAMES CAN HAVE A TREE-LIKE STRUCTURE SO THAT A RELATIVE REFERENCE FROM A DOCUMENT IN A BUFFER CAN BE RESOLVED AS POINTING TO ANOTHER BUFFER.
FOR INSTANCE, IF WE INVOKE SABLOTRON SPECIFYING THAT A
BUFFER NAMED /MYBUF/1
CONTAINS THE STRING
"&LT;A>CONTENTS&LT;/A>", THEN THE EXPRESSION
DOCUMENT('ARG:/MYBUF/1')/A
HAS STRING-VALUE "CONTENTS". IF THE DOCUMENT IN ARG:/MYBUF/1 CONTAINED A RELATIVE URI REFERENCE "../THEIRBUF/2" THEN THIS WOULD BE RESOLVED AS POINTING TO "ARG:/THEIRBUF/2".
BY DEFAULT, SABLOTRON WRITES ERROR AND WARNING MESSAGES TO
STDERR, AND DOES NO LOGGING. BY A CALL TO
SABLOTSETLOG()
, YOU CAN SPECIFY THE NAME OF THE LOG
FILE TO BE USED.
BESIDES, YOU CAN USE SABLOTREGHANDLER()
TO OVERRIDE THE DEFAULT MESSAGE HANDLING. THE HANDLER YOU
REGISTER WILL RECEIVE ALL MESSAGES IN A STRUCTURED FORM THAT'S
EASY TO PROCESS AND FILTER. FOR DETAILS, SEE
THE DOCUMENTATION IN SABLOT.H
AND
SHANDLER.H
.
THIS SECTION DESCRIBES THE FUNCTIONS EXPORTED FROM THE SABLOTRON LIBRARY. ALL OF THEM HAVE A RETURN TYPE OF 'INT' AND RETURN AN ERROR FLAG (NONZERO SIGNALS AN ERROR). ERRORS ARE REPORTED TO THE USER BY SABLOTRON ITSELF.
WE'LL FIRST DESCRIBE THE 'SHORTCUTS' THAT DO THE WHOLE PROCESSING IN ONE CALL.
INT SABLOTPROCESS(CHAR *SHEETURI, CHAR *INPUTURI, CHAR *RESULTURI,
CHAR **PARAMS, CHAR **ARGUMENTS, CHAR **RESULTARG);
THIS IS THE BASIC FUNCTION. THE FIRST THREE OF ITS ARGUMENTS ARE THE URIS OF THE XSLT STYLESHEET, THE XML SOURCE AND THE RESULTING DOCUMENT, RESPECTIVELY. FOR SOME NOTES ON SPECIFYING FILE NAMES, SEE ABOVE.
PARAMS
IS AN ARRAY OF POINTERS TO THE NAMES
AND CONTENTS OF THE TOP-LEVEL STYLESHEET PARAMETERS. THUS,
PARAMS[0]
IS A POINTER TO THE NULL-TERMINATED NAME
OF THE FIRST PARAMETER, PARAMS[1]
POINTS TO THE
(NULL-TERMINATED) CONTENTS OF THE FIRST PARAMETER. THE FOLLOWING
TWO ARRAY ITEMS DO THE SAME FOR THE SECOND PARAMETER, ETC. THE
WHOLE ARRAY IS TERMINATED BY A NULL POINTER IN PLACE OF THE
NAME. IF NO PARAMETERS ARE TO BE PASSED, YOU CAN SPECIFY NULL
FOR PARAMS
ITSELF.
ARGUMENTS
IS A SIMILAR ARRAY OF NAMED BUFFERS
TO BE PASSED TO THE STYLESHEET. (THEY CAN BE REFERRED TO VIA THE
'ARG:' SCHEME, SEE ABOVE.) AGAIN, THE
ARRAY IS A SEQUENCE OF (NAME, VALUE) PAIRS TERMINATED BY NULL IN
PLACE OF A NAME. IF NO NAMED BUFFERS ARE TO BE PASSED, YOU CAN
SPECIFY NULL FOR ARGUMENTS
ITSELF.
RESULTARG
ENABLES ONE TO ACCESS THE
RESULTING DOCUMENT IN CASE THE OUTPUT WENT TO A NAMED BUFFER. IN
THAT SITUATION, *RESULTARG
POINTS TO THE RESULTING
NULL-TERMINATED STRING, ALLOCATED BY SABLOTRON. YOU CAN PASS NULL
FOR RESULTARG
IF THE OUTPUT IS SURE TO GO TO A
FILE.
NOTE:WHEN YOU ARE DONE PROCESSING THE STRING
POINTED TO BY *RESULTARG
, FREE IT USING
SABLOTFREE()
- NEVER USE
FREE()
. THE LATTER IS GUARANTEED TO PRODUCE A
SEGMENTATION FAULT UNDER LINUX.
INT SABLOTPROCESSFILES(CHAR *STYLESHEETNAME,
CHAR *INPUTNAME,
CHAR *RESULTNAME);
A WRAPPER FOR SABLOTPROCESS()
WORKING ON
FILES. THE PARAMETERS ARE THE NULL-TERMINATED FILE NAMES OF THE
XSLT STYLESHEET, THE XML INPUT AND THE RESULT,
RESPECTIVELY. SABLOTRON OPENS THESE FILES ITSELF AND CLOSES THEM
AFTER THE PROCESSING IS COMPLETE. VALUES LIKE "FILE://STDIN" ARE
ALLOWED.
INT SABLOTPROCESSSTRINGS(CHAR *STYLESHEETSTR, CHAR *INPUTSTR, CHAR
**RESULTSTR);
ANOTHER WRAPPER FOR SABLOTPROCESS()
, THIS
TIME FOR ACCESSING NAMED BUFFERS (I.E. USER-ALLOCATED MEMORY
BLOCKS)ONLY. THUS, THE FIRST PARAMETER IS A NULL-TERMINATED
STRING CONTAINING THE WHOLE STYLESHEET; THE SECOND PARAMETER
IS A NULL-TERMINATED STRING CONTAINING THE XML
INPUT. SABLOTRON ALLOCATES THE BUFFER FOR THE RESULTING STRING
AND RETURNS A POINTER TO IT IN RESULTSTR. HENCE, INVOKING
PUTS(*RESULTSTR)
AFTER HAVING CALLED
SABLOTPROCESSSTRINGS
SENDS THE RESULT TO
STDOUT. THE BUFFER ALLOCATED MUST BE FREED BY CALLING THE
FUNCTION SABLOTFREE
DESCRIBED NEXT.
THE ABOVE SHORTCUTS JUST CALL THE BASIC, LOWER-LEVEL FUNCTIONS DESCRIBED BELOW. NOTE THAT IF YOU NEED TO SET OPTIONS FOR LOGGING ETC., YOU MAY NEED TO USE THE LOW-LEVEL FUNCTIONS.
A TYPICAL PROCESSING SESSION MAY LOOK LIKE THIS:
SABLOTHANDLE P; CHAR *MY_BUF; SABLOTCREATEPROCESSOR(&P); SABLOTSETLOG(P, ...); /* ...SET OTHER INSTANCE-SPECIFIC OPTIONS HERE... */ SABLOTRUNPROCESSOR(P, ...); SABLOTGETRESULTARG(P, "ARG:/SOMENAME", &MY_BUF) /* ...DO SOMETHING WITH MY_BUF... */ /* CAN RUN THE PROCESSOR AGAIN IF NECESSARY */ SABLOTRUNPROCESSOR(P, ...); SABLOTDESTROYPROCESSOR(P);
INT SABLOTCREATEPROCESSOR(SABLOTHANDLE *PROCESSORPTR);
CREATES AN INSTANCE OF SABLOTRON AND RETURNS A POINTER TO IT IN *PROCESSORPTR. THIS POINTER IS PASSED ON ALL SUBSEQUENT CALLS TO THIS INSTANCE.
INT SABLOTDESTROYPROCESSOR(SABLOTHANDLE PROCESSOR_);
DESTROYS AN INSTANCE OF THE PROCESSOR, DEALLOCATING ALL THE MEMORY USED UP BY IT.
INT SABLOTRUNPROCESSOR(SABLOTHANDLE PROCESSOR_,
CHAR *SHEETURI,
CHAR *INPUTURI,
CHAR *RESULTURI,
CHAR **PARAMS,
CHAR **ARGUMENTS);
PROCESSES DOCUMENTS USING THE GIVEN PROCESSOR INSTANCE AND
GIVEN PARAMS AND ARGS DEFINITIONS. SEE
SABLOTPROCESS()
.
INT SABLOTGETRESULTARG(SABLOTHANDLE PROCESSOR_,
CHAR *ARGURI,
CHAR **ARGVALUE);
COPIES THE RESULT 'ARG' BUFFER WITH THE GIVEN URI, RETURNING A POINTER TO THE NEWLY-ALLOCATED BLOCK IN *ARGVALUE. IF NO SUCH BUFFER EXISTS, RETURNS NULL IN *ARGVALUE.
THIS FUNCTION IS NECESSARY, BECAUSE IF THE RESULT DOCUMENT
IS OUTPUT TO MEMORY, IT WOULD BE LOST WHEN
SABLOTDESTROYPROCESSOR()
IS CALLED. WHEN
DEALLOCATING THE COPY OBTAINED FROM
SABLOTGETRESULTARG()
, USE SABLOTFREE
(NEVER FREE()
).
INT SABLOTFREERESULTARGS(SABLOTHANDLE PROCESSOR_);
REMOVES THE SABLOTRON-INTERNAL COPIES OF THE 'ARG' BUFFERS
FROM THE LAST SABLOTRON RUN. NORMALLY, THERE SHOULD BE NO REASON
TO CALL THIS FUNCTION AS IT IS CALLED AUTOMATICALLY ON BOTH
SABLOTRUNPROCESSOR()
AND
SABLOTDESTROYPROCESSOR()
.
INT SABLOTFREE(CHAR *RESULTBUF);
THIS FUNCTION FREES THE BUFFER ALLOCATED ON PREVIOUS CALL
TO SABLOTPROCESSSTRINGS
. CALLING IT WITH AN
INVALID POINTER WILL CAUSE A CRASH.
INT SABLOTREGHANDLER(
SABLOTHANDLE PROCESSOR_,
HANDLERTYPE TYPE,
VOID *HANDLER,
VOID *USERDATA);
REGISTERS AN EXTERNAL HANDLER. TYPE
CAN BE
HLR_MESSAGE
, HLR_SCHEME
,
HLR_SAX
, HLR_MISC
OR
HLR_ENC
.
HANDLER
POINTS TO THE
CALLBACK VECTOR OF THE APPROPRIATE TYPE. USERDATA
IS A DATA ITEM TO PASSED TO ALL CALLBACKS OF THIS PARTICULAR
HANDLER. FOR DETAILS, CHECK THE SABLOT.H
AND
SHANDLER.H
HEADER FILES.
INT SABLOTUNREGHANDLER(
SABLOTHANDLE PROCESSOR_,
HANDLERTYPE TYPE,
VOID *HANDLER,
VOID *USERDATA);
UNREGISTERS THE GIVEN EXTERNAL HANDLER. FOR DETAILS, CHECK THE
SABLOT.H
AND SHANDLER.H
HEADER
FILES.
INT SABLOTSETLOG(
SABLOTHANDLE PROCESSOR_,
CONST CHAR *LOGFILENAME,
INT LOGLEVEL);
SETS THE LOG FILENAME. THE LOGLEVEL
PARAMETER
IS CURRENTLY NOT USED. PASS NULL FOR LOGFILENAME
TO
TURN LOGGING OFF (DEFAULT).
THE OTHER FUNCTIONS PUBLISHED BY SABLOT.H HAVE BEEN INCLUDED FOR EXPERIMENTAL REASONS OR FOR COMPATIBILITY, AND IT IS BETTER NOT TO USE THEM.
INT SABLOTCLEARERROR(SABLOTHANDLE PROCESSOR_);
CLEARS THE 'PENDING ERROR' FLAG FOR THIS INSTANCE OF SABLOTRON.
THE IMPLEMENTATION OF THE DOM INTERFACE BROUGHT THE NEED TO EXTEND SOME OF THE FUNCTIONS DESCRIBED IN THE PREVIOUS SECTION. THIS EXTENSION ENABLES THE USER TO:
AN OBJECT CALLED SITUATION IS USED TO PROVIDE A PERSISTENT CONTEXT FOR ALL CALLS TO THE DOM-RELATED FUNCTIONS. FUNCTIONS USED TO MANIPULATE THE SITUATION ARE DESCRIBED IN THE FOLLOWING SECTION.
NOTE: IF NOT SPECIFIED OTHERWISE, ALL THESE FUNCTIONS RETURN AN ERROR CODE. A POSITIVE VALUE INDICATES AN ERROR.
INT SABLOTCREATEDOCUMENT(SABLOTSITUATION S,
SDOM_DOCUMENT *D);
CREATES AN EMPTY DOCUMENT. TYPICALLY FOLLOWED BY CALLS TO DOM FUNCTIONS TO POPULATE THE DOCUMENT.
INT SABLOTDESTROYDOCUMENT(SABLOTSITUATION S,
SDOM_DOCUMENT D);
DESTROYS A DOCUMENT, FREEING ALL THE NODES IT HAS CREATED.
INT SABLOTPARSE(SABLOTSITUATION S,
CONST CHAR *URI, SDOM_DOCUMENT *D);
READS IN A DOCUMENT FROM THE GIVEN URI.
INT SABLOTPARSEBUFFER(SABLOTSITUATION S,
CONST CHAR *BUFFER, SDOM_DOCUMENT *D);
READS IN A DOCUMENT FROM THE GIVEN IN-MEMORY BUFFER.
THESE FUNCTIONS HAVE VARIANTS TO BE USED IF THE DOCUMENT
IS TO BE INTERPRETED AS AN XSLT STYLESHEET, NAMELY
SABLOTPARSESTYLESHEET
AND
SABLOTPARSESTYLESHEETBUFFER
.
THE FOLLOWING FUNCTIONS GENERALIZE
SABLOTRUNPROCESSOR
IN THAT THEY MAKE IT POSSIBLE TO
UTILIZE AN EXTRA KIND OF A SOURCE DOCUMENT: A DOM TREE.
INT SABLOTRUNPROCESSORGEN(SABLOTSITUATION S,
VOID *PROCESSOR_,
CHAR *SHEETURI,
CHAR *INPUTURI,
CHAR *RESULTURI);
A KEY INGREDIENT OF THE EXTENDED INTERFACE. ONLY THE URIS
OF THE SOURCES AND OF THE RESULT DOCUMENT ARE GIVEN TO IT. THE
REST OF THE INFORMATION PASSED TO
SABLOTRUNPROCESSOR
IS CONVEYED THROUGH
SABLOTADDARGBUFFER,
SABLOTADDARGTREE
AND SABLOTADDPARAM.
THE SCHEME PART OF THE
STYLESHEET URI OR THE INPUT URI MAY BE "ARG:", IN WHICH
CASE THEY REFER TO A BUFFER OR TREE PASSED BY THESE
FUNCTIONS.
INT SABLOTADDARGBUFFER(SABLOTSITUATION S,
VOID *PROCESSOR_,
CONST CHAR *ARGNAME,
CONST CHAR *BUFFERVALUE);
CREATES A NAMED BUFFER FOR THE NEXT PROCESSOR RUN. THE BUFFER'S NAME AND CONTENTS ARE PASSED AS ARGUMENTS. THE NAME IS INTERPRETED RELATIVE TO THE 'ARG:/' SCHEME.
INT SABLOTADDARGTREE(SABLOTSITUATION S,
VOID *PROCESSOR_,
CONST CHAR *ARGNAME,
SDOM_DOCUMENT TREE);
ASSOCIATES THE GIVEN DOCUMENT WITH A NAME FOR THE NEXT PROCESSOR RUN. THE DOCUMENT IS NOT DESTROYED AFTER THE RUN IS FINISHED. THE NAME IS INTERPRETED RELATIVE TO THE 'ARG:/' SCHEME.
INT SABLOTADDPARAM(SABLOTSITUATION S,
VOID *PROCESSOR_,
CONST CHAR *PARAMNAME,
CONST CHAR *PARAMVALUE);
ADDS A GLOBAL STYLESHEET PARAMETER FOR THE NEXT PROCESSOR RUN.
AT PRESENT, THE SITUATION OBJECT PRIMARILY HOLDS INFORMATION ON ANY PENDING ERRORS. A SITUATION IS CREATED USING
INT SABLOTCREATESITUATION(SABLOTSITUATION
*SP);
AND DESTROYED BY
INT SABLOTDESTROYSITUATION(SABLOTSITUATION
S);
TO CLEAR THE PENDING ERROR FLAG IN A SITUATION, USE
INT SABLOTCLEARSITUATION(SABLOTSITUATION
S);
THE FOLLOWING SELF-EXPLANATORY FUNCTIONS EXTRACT PARTS OF THE ERROR INFORMATION FROM THE SITUATION:
CONST CHAR *SABLOTGETERRORURI(SABLOTSITUATION S);
INT SABLOTGETERRORLINE(SABLOTSITUATION S);
CONST CHAR *SABLOTGETERRORMSG(SABLOTSITUATION S);
STARTING WITH VERSION 0.60, SABLOTRON IMPLEMENTS
A MAJOR SUBSET OF THE DOM LEVEL 1 CORE SPECIFICATION [DOM]. A BRIEF
DESCRIPTION OF THE IMPLEMENTED INTERFACE FOLLOWS; FOR MORE
DETAILS, PLEASE REFER TO THE HEADER FILE NAMED
SDOM.H.
ALL OF THE NAMES RELATED TO THE DOM INTERFACE START WITH SDOM_ (FOR SABLOT DOM).
MAJOR NEW TYPES ARE SDOM_DOCUMENT
(A DOM TREE) AND
SDOM_NODE
(A NODE OF THE TREE). A DOCUMENT CAN ALSO BE USED IN
PLACE OF A NODE. THIS REFLECTS THE FACT IN THE DOM SPEC,
DOCUMENT IS A SUBCLASS OF NODE. WHEN USED IN THIS WAY, THE
DOCUMENT REPRESENTS ITS OWN ROOT NODE (WHICH IS NOT THE SAME AS
THE `ROOT ELEMENT').
OTHER TYPES INCLUDE:
SDOM_CHAR:
A DOM CHARACTER TYPE. CURRENTLY, THIS IS JUST
CHAR. NOTE THAT THE DOM SPEC REQUIRES THAT THE DOM
IMPLEMENTATIONS WORK WITH UTF-16. SABLOTRON DEVIATES FROM THIS
BY USING UTF-8 INSTEAD. A SEPARATE SET OF FUNCTIONS TAKING
UTF-16 STRINGS WILL BE PROVIDED.SDOM_NODETYPE:
A NODE TYPE ENUM. SOME OF THE VALUES ARE
SDOM_ELEMENT_NODE,
SDOM_ATTRIBUTE_NODE
AND SDOM_TEXT_NODE.
SEE
SDOM.H
FOR THE REST.SDOM_NODELIST:
A NODE LIST RETURNED BY SOME OF THE
FUNCTIONS.SDOM_EXCEPTION:
DOM EXCEPTION CODES ENUM, WITH VALUES SUCH
AS SDOM_NOT_FOUND_ERR
OR SDOM_INVALID_NODE_TYPE
. SEE SDOM.H
FOR DETAILS.THE FUNCTIONS LISTED BELOW ARE IMPLEMENTED MORE OR LESS AS DEFINED IN
THE DOM LEVEL 1 SPECIFICATION, WITH TWO EXCEPTIONS:
THEIR NAMES ARE PREFIXED WITH SDOM_
AND THE FIRST ARGUMENT IS
ALWAYS A SABLOTSITUATION.
ALL THE FUNCTIONS RETURN
A SDOM_EXCEPTION.
CREATEELEMENT, CREATEATTRIBUTE, CREATETEXTNODE,
CREATECDATASECTION, CREATECOMMENT, CREATEPROCESSINGINSTRUCTION
GETNODETYPE, GETNODENAME, SETNODENAME, GETNODEVALUE, SETNODEVALUE
GETPARENTNODE, GETFIRSTCHILD, GETLASTCHILD, GETPREVIOUSSIBLING,
GETNEXTSIBLING, GETOWNERDOCUMENT
INSERTBEFORE, APPENDCHILD, REMOVECHILD, REPLACECHILD
CLONENODE
GETATTRIBUTE, SETATTRIBUTE, REMOVEATTRIBUTE, GETATTRIBUTELIST
SEVERAL FUNCTIONS HAVE BEEN ADDED:
DISPOSENODE
FREES ALL MEMORY USED BY THE GIVEN NODECLONEFOREIGNNODE
CLONES A NODE FROM A DIFFERENT
DOCUMENTDOCTOSTRING
SERIALIZES THE DOCUMENT, RETURNING THE
RESULTING STRINGXQL
PERFORMS AN XPATH QUERY ON THE DOM TREE,
RETURNING A LIST OF THE NODES SATISFYING IT.IN ADDITION, THERE ARE SOME FUNCTIONS USED TO MANIPULATE
THE NODE LISTS RETURNED BY XQL
AND
GETATTRIBUTELIST
. THESE INCLUDE
GETNODELISTLENGTH
, GETNODELISTITEM
AND
DISPOSENODELIST
.
FINALLY, THERE ARE FUNCTIONS TO EXTRACT DOM
EXCEPTION-RELATED INFORMATION FROM THE SITUATION OBJECT, NAMELY
GETEXCEPTIONCODE
, GETEXCEPTIONMESSAGE
AND GETEXCEPTIONDETAILS
.
SABLOTRON COMES WITH A COMMAND-LINE INTERFACE TO THE
SHARED LIBRARY, WHICH IS A PROGRAM NAMED
SABCMD
. AT PRESENT, SABCMD
IS INVOKED
AS FOLLOWS:
SABCMD [OPTIONS] STYLESHEET [INPUT [RESULT]] [ASSIGNMENTS]
THE ARGUMENTS ARE THE URIS OF THE XSLT STYLESHEET, THE
XML INPUT DOCUMENT, AND THE RESULTING DOCUMENT, RESPECTIVELY. THE
DEFAULT FOR
INPUT
IS
FILE://STDIN
(MEANING PLAIN OLD STDIN);
RESULT
DEFAULTS TO
FILE://STDOUT
. FILENAMES HAVE TO INCLUDE THE EXTENSION (IF
ANY).
YOU CAN DISPLAY THE LIST OF AVAILABLE OPTIONS BY TYPING
SABCMD --HELP
. AMONG THE MORE USEFUL ONES ARE
--LOG-FILE
(FOR SETTING THE LOG FILE) AND
--MEASURE
(MEASURES AND OUTPUTS THE TOTAL
PROCESSING TIME).
THE RULES FOR FILENAMES ARE THE SAME AS
WITH SABLOTPROCESS()
.
ASSIGNMENTS
IS A SERIES OF DEFINITIONS OF THE
FORM:
NAME1=VALUE1 NAME2=VALUE2 ...
ASSIGNING VALUES TO TOP-LEVEL STYLESHEET PARAMETERS AND TO NAMED BUFFERS. THESE TWO CASES ARE DISTINGUISHED BY A LEADING '$' IN THE NAME OF A STYLESHEET PARAMETER. THE NAMES OF THE BUFFERS DO NOT START WITH "ARG:". THEY MAY START WITH A SLASH; IF THEY DON'T, THE SLASH IS PREPENDED.
NOTE: IN MOST CASES, IT WILL BE NECESSARY TO QUOTE THE INDIVIDUAL ASSIGNMENTS. WHETHER TO USE SINGLE OR DOUBLE QUOTES MAY DEPEND ON THE SHELL USED (OR MAY IT?) SINGLE QUOTES WORK FOR BASH, DOUBLE QUOTES WORK IN WINDOWS.
IF THE RESULT URI REFERS TO A NAMED BUFFER, THE OUTPUT WOULD NORMALLY REMAIN BURIED IN MEMORY. SABCMD DUMPS THE BUFFER TO STANDARD OUTPUT INSTEAD.
TO SUM UP AND GIVE AN EXAMPLE, THE FOLLOWING WOULD BE A VALID INVOCATION OF SABCMD:
SABCMD SHEET.XSL ARG:/THE_INPUT "THE_INPUT=&LT;A/>"
"$USE_DEFAULTS=1"
THIS PROCESSES THE DOCUMENT PASSED IN THE BUFFER NAMED THE_INPUT, USING A STYLESHEET FOUND IN FILE "SHEET.XSL" IN THE WORKING DIRECTORY. WE ASSIGN 1 TO THE TOP-LEVEL PARAMETER CALLED "USE_DEFAULTS". THE OUTPUT GOES TO STDOUT BY DEFAULT.
(C) 2000 GINGER ALLIANCE S.R.O.