Re: [xslt] Rework locale feature tests

2018-01-11 Thread Vojtech Fried
>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
 *

Re: [xslt] Rework locale feature tests

2018-01-09 Thread Nick Wellnhofer

On 09/01/2018 12:47, Vojtech Fried wrote:

I think there never was a configure option for locale support. It certainly
isn't a feature that was removed.

I would have to check for unix, but for windows, there was a support for turning locales 
off (via configure.js). And it was removed in the commit "Rework locale feature 
tests".


For Windows, that's possible. I was thinking about UNIX.


A custom sort function overrides the internal sort function. It shouldn't
matter whether libxslt is compiled with locale support or not.

My sorting function (slightly modified version of libxslt/examples/ 
xsltICUSort.c) internally calls xsltComputeSortResult, which uses a locale if 
set. Maybe my sorting function could deal with it (e.g. it could have its own 
version of xsltComputeSortResult), but the easiest way was to turn locale 
support off completely. I do not need it, since I do the sort myself.


I see. I'd suggest to use your own version of xsltComputeSortResult from 
libxslt/xsltutils.c and remove the following lines:


if (comp->locale != (xsltLocale)0) {
xmlChar *str = res->stringval;
res->stringval = (xmlChar *) xsltStrxfrm(comp->locale, str);
xmlFree(str);
}

Nick
___
xslt mailing list, project page http://xmlsoft.org/XSLT/
xslt@gnome.org
https://mail.gnome.org/mailman/listinfo/xslt


Re: [xslt] Rework locale feature tests

2018-01-09 Thread Vojtech Fried
>> I have tried to update my libxml & libxslt used in my project. One problem I 
>> see is with sorting and locales. I used to use (a modified version of) 
>> xsltICUSort.c (in xslt/examples) to do sorting. (I can send you my version, 
>> if 
>> you are interested, but it is a long time since I did the changes and I do 
>> not 
>> remember the details) If I remember right it required to turn the locale 
>> support off. This is no longer possible.
>I think there never was a configure option for locale support. It certainly 
>isn't a feature that was removed.
I would have to check for unix, but for windows, there was a support for 
turning locales off (via configure.js). And it was removed in the commit 
"Rework locale feature tests".

>> I tried the new implementation of sort, but I get different results in my 
>> project tests. E.g. sort without lang works in a different way. Sort with 
>> lang 
>> handles upper/lower case sorting in a different way.
>Maybe the behavior of the underlying ICU library changed?
No, I am comparing the results of my ICU based compare function to the official 
locale based sorting.

>A custom sort function overrides the internal sort function. It shouldn't 
>matter whether libxslt is compiled with locale support or not.
My sorting function (slightly modified version of libxslt/examples/ 
xsltICUSort.c) internally calls xsltComputeSortResult, which uses a locale if 
set. Maybe my sorting function could deal with it (e.g. it could have its own 
version of xsltComputeSortResult), but the easiest way was to turn locale 
support off completely. I do not need it, since I do the sort myself.

Vojtech
___
xslt mailing list, project page http://xmlsoft.org/XSLT/
xslt@gnome.org
https://mail.gnome.org/mailman/listinfo/xslt


Re: [xslt] Rework locale feature tests

2018-01-08 Thread Nick Wellnhofer

On 15/12/2017 12:43, Vojtech Fried wrote:
I have tried to update my libxml & libxslt used in my project. One problem I 
see is with sorting and locales. I used to use (a modified version of) 
xsltICUSort.c (in xslt/examples) to do sorting. (I can send you my version, if 
you are interested, but it is a long time since I did the changes and I do not 
remember the details) If I remember right it required to turn the locale 
support off. This is no longer possible.


I think there never was a configure option for locale support. It certainly 
isn't a feature that was removed.


I tried the new implementation of sort, but I get different results in my 
project tests. E.g. sort without lang works in a different way. Sort with lang 
handles upper/lower case sorting in a different way.


Maybe the behavior of the underlying ICU library changed?

And I have a vague 
memory, that you have to have system support for the locales for them to 
actually work, which is not what I want, I want the sort to work on any system 
in any configuration.


A custom sort function overrides the internal sort function. It shouldn't 
matter whether libxslt is compiled with locale support or not.


Is using an external sorting function still a supported feature? Would you 
consider reintroducing the possibility to turn off locale support?


External sort functions are still supported. It's possible that something 
broke in libxslt but we'd need more details.


Nick
___
xslt mailing list, project page http://xmlsoft.org/XSLT/
xslt@gnome.org
https://mail.gnome.org/mailman/listinfo/xslt