>I see. I'd suggest to use your own version of xsltComputeSortResult from
>libxslt/xsltutils.c and remove the following lines:
Ok, I did it, it works.
FYI, attached is my updated sorting function. (Although I actually use a
slightly different one, a C++ version, so this version is not tested)
/Vojtech
/**
* xsltICUSort.c: module provided by Richard Jinks to provide a
*sort function replacement using ICU, it is not
*included in standard due to the size of the ICU
*library
*
* See http://mail.gnome.org/archives/xslt/2002-November/msg00093.html
* http://oss.software.ibm.com/icu/index.html
*
* Copyright Richard Jinks
*/
#define IN_LIBXSLT
#include "libxslt.h"
#include
#include "xsltconfig.h"
#include "xslt.h"
#include "xsltInternals.h"
#include "xsltutils.h"
#include "transform.h"
#include "templates.h"
#include
#include
#include
#include
#include
/**
* xsltICUComputeSortResult:
* @ctxt: a XSLT process context
* @sort: node list
*
* reorder the current node list accordingly to the set of sorting
* requirement provided by the array of nodes.
*
* Returns a ordered XPath nodeset or NULL in case of error.
*/
xmlXPathObjectPtr *
xsltICUComputeSortResult(xsltTransformContextPtr ctxt, xmlNodePtr sort) {
#ifdef XSLT_REFACTORED
xsltStyleItemSortPtr comp;
#else
xsltStylePreCompPtr comp;
#endif
xmlXPathObjectPtr *results = NULL;
xmlNodeSetPtr list = NULL;
xmlXPathObjectPtr res;
int len = 0;
int i;
xmlNodePtr oldNode;
xmlNodePtr oldInst;
int oldPos, oldSize ;
int oldNsNr;
xmlNsPtr *oldNamespaces;
comp = sort->psvi;
if (comp == NULL) {
xsltGenericError(xsltGenericErrorContext,
"xsl:sort : compilation failed\n");
return(NULL);
}
if ((comp->select == NULL) || (comp->comp == NULL))
return(NULL);
list = ctxt->nodeList;
if ((list == NULL) || (list->nodeNr <= 1))
return(NULL);
len = list->nodeNr;
/* TODO: xsl:sort lang attribute */
/* TODO: xsl:sort case-order attribute */
results = xmlMalloc(len * sizeof(xmlXPathObjectPtr));
if (results == NULL) {
xsltGenericError(xsltGenericErrorContext,
"xsltICUComputeSortResult: memory allocation failure\n");
return(NULL);
}
oldNode = ctxt->node;
oldInst = ctxt->inst;
oldPos = ctxt->xpathCtxt->proximityPosition;
oldSize = ctxt->xpathCtxt->contextSize;
oldNsNr = ctxt->xpathCtxt->nsNr;
oldNamespaces = ctxt->xpathCtxt->namespaces;
for (i = 0;i < len;i++) {
ctxt->inst = sort;
ctxt->xpathCtxt->contextSize = len;
ctxt->xpathCtxt->proximityPosition = i + 1;
ctxt->node = list->nodeTab[i];
ctxt->xpathCtxt->node = ctxt->node;
#ifdef XSLT_REFACTORED
if (comp->inScopeNs != NULL) {
ctxt->xpathCtxt->namespaces = comp->inScopeNs->list;
ctxt->xpathCtxt->nsNr = comp->inScopeNs->xpathNumber;
} else {
ctxt->xpathCtxt->namespaces = NULL;
ctxt->xpathCtxt->nsNr = 0;
}
#else
ctxt->xpathCtxt->namespaces = comp->nsList;
ctxt->xpathCtxt->nsNr = comp->nsNr;
#endif
res = xmlXPathCompiledEval(comp->comp, ctxt->xpathCtxt);
if (res != NULL) {
if (res->type != XPATH_STRING)
res = xmlXPathConvertString(res);
if (comp->number)
res = xmlXPathConvertNumber(res);
res->index = i; /* Save original pos for dupl resolv */
if (comp->number) {
if (res->type == XPATH_NUMBER) {
results[i] = res;
} else {
#ifdef WITH_XSLT_DEBUG_PROCESS
xsltGenericDebug(xsltGenericDebugContext,
"xsltICUComputeSortResult: select didn't evaluate to a
number\n");
#endif
results[i] = NULL;
}
} else {
if (res->type == XPATH_STRING) {
results[i] = res;
} else {
#ifdef WITH_XSLT_DEBUG_PROCESS
xsltGenericDebug(xsltGenericDebugContext,
"xsltICUComputeSortResult: select didn't evaluate to a
string\n");
#endif
results[i] = NULL;
}
}
} else {
ctxt->state = XSLT_STATE_STOPPED;
results[i] = NULL;
}
}
ctxt->node = oldNode;
ctxt->inst = oldInst;
ctxt->xpathCtxt->contextSize = oldSize;
ctxt->xpathCtxt->proximityPosition = oldPos;
ctxt->xpathCtxt->nsNr = oldNsNr;
ctxt->xpathCtxt->namespaces = oldNamespaces;
return(results);
}
/**
* xsltICUSortFunction:
* @ctxt: a XSLT process context
* @sorts: array of sort nodes
* @nbsorts: the number of sorts in the array
*
* reorder the current node list accordingly to the set of sorting
* requirement provided by the arry of nodes.
* uses the ICU library