[xslt] Modifing parsed tree.



Hello, I have some question.

First I want a introduce my "work".  I'm using for some time xsltproc
in my DocBook processing machinery.  I switch to int in some of my
"Books", because they are a huge and Saxon crashes on it.  So xsltproc
passed testing time.

But xsltproc does not implement some extensions, Norman use in his
stylesheets.  In the extension/xsltproc directory there are some
pieces of code which in combination with Python extend the xsltproc.
But those are old and not usefull. So I choose my own way.  The WAY.

I start looking into xsltproc and exslt library. And I plan, I plan
write docbook extension to exslt library.  I'm just standing before
the mountain and trying do first steps. May be I do not succeed, but
I'll try it.

So first work is to build TableAdjustColumnWidths function.  So I
wrote some code only to see if I'm on right way and able to write some
extension.

The function does nothing now, I'm looking only if it do not breaks
other things.

================>cut<================
/**
 * exsltDBTableAdjustColumnWidths
 * @ctxt:   an XPath parser context
 * @nargs:  the number of arguments
 *
 */
static void
exsltDBTableAdjustColumnWidths (xmlXPathParserContextPtr ctxt, int nargs) {
	xmlXPathObjectPtr tree;
	int i;
	
	dump_xmlXPathParserContext(ctxt, DUMP_DEEP, "ctxt", "context before any processing", 0);

#ifdef WITH_XSLT_DEBUG_FUNCTION
	xsltGenericDebug(xsltGenericDebugContext,
			 "libxslt:exsltDBTableAdjustColumnWidths() called with %d args\n", nargs);
#endif
	
	/* The number of passed arguments should be one. */
	if (nargs != 1) xmlXPathSetArityError(ctxt); /* check the count */

	/* Geting arguments:
	 * I do not found function for poping XSLT_TREE object from
	 * argument stack.  The PopNodeSet isn't good way how to get
	 * it.
	 * ERROR:cols = xmlXPathPopNodeSet(ctxt);
	 * So I access the value directly from XPathParserContext
	 * structure without modifiing the structure.
	 */
	tree = ctxt->value;
	//tree = valuePop(ctxt); //!!!valuePop,valuePush doesn't work for me.

	dump_xmlXPathObject(tree, DUMP_DEEP, "tree", "Poped nodeset from ctxt", 0);
	dump_xmlXPathParserContext(ctxt, DUMP_DEEP, "ctxt", "After valuePop(ctxt)", 0);

	if(xmlXPathCheckError(ctxt)) {
		xsltGenericError(xsltGenericErrorContext,
				 "DB:TableAdjustColumnWidths: XPathCheckError\n");
		return;
	}
	
	/* Traverse the tree here:
	 */


	dump_xmlXPathObject_simple(tree, "tree", 5, 0);

	/* Return columns */
	//valuePush(ctxt, tree); //!!!valuePop,valuePush doesn't work for me.

} /* exsltDBTableAdjustColumnWidths */
===============>cut<==================

For now it does not break things as I see. But ...
There is in documentation
http://xmlsoft.org/html/libxml-xpath.html#XPATH_XSLT_TREE some comment
there:

    XPATH_XSLT_TREE = 9 : An XSLT value tree, non modifiable

And I'm not sure what to do with it.  Firstly I think that I simply
traverse the tree and do necessary modification as the DocBook
stylesheet needs.  But now I'm not sure if it's the right way.

So. Am I allowed to make sillently some "minor" modification of parsed
tree, or have I construct completly new tree following the original
parsed tree?

If I have construct new tree, can someone point me to code which
construct some.


--
Please feel free to flame me with "RTFM", just as long as you tell me
where in TFM I have to R.


-- 
Podepsána, swojí Wlastní rukou, jejich przeweliká dobrotiwost a pán
sítí jejich, jenz wládne nad pakety a smerowaci wsemi.

Radek Hnilica <Radek.Hnilica at Moraviapress dot CZ>
Radek Hnilica <Radek.Mobile at Moraviapress dot CZ>
Radek Hnilica <Radek at Hnilica dot CZ>  http://www.hnilica.cz
==============================================================
No matter how far down the wrong road you've gone, turn back.
						Turkish proverb
... so turn back ... Now!



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]