GNOME Bugzilla – Bug 59220
enh: allow stylesheet parameter to be treated literally
Last modified: 2009-08-15 18:40:50 UTC
I am trying to define a stylesheet parameter which might contain both single and double quotes. The existing mechanism for stylesheet parameters doesn't handle this. I have implemented a workaround, but it requires some changes to the standard 1.0.1 release. Strictly speaking, this code belongs in variable.c, but I like to keep the changes to the gnome source code to a minimum so I have them in a separate file, otherwise item (a) would be unnecessary. I'm not using namespaces with my parameters, so I skipped that part. I don't really understand how they apply to parameters. a. In file variables.c the routines xsltNewStackElem and xsltFreeStackElem must be made non-static and their prototypes added to variables.h b. In transform.c near line 3242 in xsltApplyStyleSheetInternal old: ctxt->globalVars = xmlHashCreate(20); new: if (ctxt->globalVars == NULL) ctext->globalVars = xmlHashCreate(20); With these changes, I can create a context in my main program, add parameters treated literally (below) and then call xsltApplyStyleSheetUser. Without item (b) the hash table will be reinitialized. ================================================================= /** * File XT_storeGnomeParam.cpp * * If a parameter is passed to Gnome as part of the standard routine * xsltApplyStyleSheetInternal (or xsltApplyStyleSheetUser) treats the * parameters as XPath expressions. This would be ok, except that it can't * handle the case where a parameter contains both an apostrophe and a * double quote. * * This routine allows the caller to insert a parameter as a literal string * in the parameter table of the transform context, bypassing the problem. * * This routine makes copies of the value beause it is too difficult to manage * the lifetime. When the transform context is destroyed it automatically * deallocates everything related to the variable/parameter hash table - thus * the caller should not deallocate these items. * * Derived from Gnome libxslt routine xsltEvalUserParams in variables.c. * * In order to be consistent with xsltEvalUserParam this routine returns * (-1) for failure and 0 for success. */ #include "libxslt/libxslt.h" #include <libxml/xpathInternals.h> #include "libxslt/xsltutils.h" #include "libxslt/variables.h" #include <memory.h> #include "svc/hdr/xt/XT_XslTransformer.H" int XT_XslTransformer::storeGnomeParam(xsltTransformContextPtr ctxt, xmlChar * name, xmlChar * value) { xsltStackElemPtr elem = NULL; int pretendResult = 0; if (ctxt == NULL) return (-1); if (name == NULL) return (-1); if (value == NULL) return (-1); elem = xsltNewStackElem(); if (elem == NULL) return (-1); memset(elem, 0, sizeof(xsltStackElem)); elem->name = xmlStrdup(name); if (elem->name == NULL) return (-1); elem->select = xmlStrdup(value); if (elem->select == NULL) return (-1); elem->computed = 1; // The elem value must be allocated independently because the hash // table free routines will deallocate it independently from the // elem select value. elem->value = xmlXPathWrapString(xmlStrdup(value)); /* * Global parameters are stored in the XPath context * variables pool. */ if (ctxt->globalVars == NULL) ctxt->globalVars = xmlHashCreate(20); pretendResult = xmlHashAddEntry2(ctxt->globalVars, name, NULL, elem); if (pretendResult != 0) { xsltFreeStackElem(elem); xsltPrintErrorContext(ctxt, ctxt->style, NULL); xsltGenericError(xsltGenericErrorContext, "Global parameter %s already defined\n", name); } return 0; }
Okay I did b/ this will be in the next release. I think this is sufficient to consider the bug fixed. Whether an extra routine should be added to provide the functionality directly, why not, but provide a C one and the associated comment template, that's an enhancement I would agree on if I get the code :-) thanks, Daniel
Created attachment 5039 [details] zip of libxslt/variables.* and short text file description
I have attached a zip file containing a revised version of xsltEvalUserParams and a short description. I apologize for submitting the earlier revision which was clearly inappropriate for inclusion in libxslt. This revision is based on 1.0.3.
Hum, going through *new versions* of files is really painful. This mean I have to *remember* whether any change between the version you submitted and what is in my own tree is something which got commited to the tree or is one of your changes I cannot take your file and copy it over, this is impossible, make patches next time please. Also providing a 3 page long text for me to analyze on various topics, some completely unrelated to the initial report is hard especially when some are related to portability. Use the list for this !It should not take me one hour to understand and process the data associated to a bug report, this can't scale ... That said I have tried to integrate those in the tree, Daniel
Shoult be closed by the 1.0.4 release, thanks, Daniel