[libxslt] Support attribute value templates in xsl:sort lang attributes
- From: Nick Wellnhofer <nwellnhof src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libxslt] Support attribute value templates in xsl:sort lang attributes
- Date: Tue, 5 Jan 2021 14:06:10 +0000 (UTC)
commit 3df643af3332f5caf8e1f1be06d5b44f77c13ed7
Author: Nick Wellnhofer <wellnhofer aevum de>
Date: Sat Dec 19 16:35:22 2020 +0100
Support attribute value templates in xsl:sort lang attributes
Also fix namespace when evaluating data-type and order attributes.
Make sure to cleanup temporary data in error case.
Fixes #47.
libxslt/xsltutils.c | 25 +++++++++++++++++++++----
1 file changed, 21 insertions(+), 4 deletions(-)
---
diff --git a/libxslt/xsltutils.c b/libxslt/xsltutils.c
index 94097b9d..bc52c761 100644
--- a/libxslt/xsltutils.c
+++ b/libxslt/xsltutils.c
@@ -1102,7 +1102,8 @@ xsltDefaultSortFunction(xsltTransformContextPtr ctxt, xmlNodePtr *sorts,
int depth;
xmlNodePtr node;
xmlXPathObjectPtr tmp;
- int tempstype[XSLT_MAX_SORT], temporder[XSLT_MAX_SORT];
+ int tempstype[XSLT_MAX_SORT], temporder[XSLT_MAX_SORT],
+ templang[XSLT_MAX_SORT];
if ((ctxt == NULL) || (sorts == NULL) || (nbsorts <= 0) ||
(nbsorts >= XSLT_MAX_SORT))
@@ -1124,7 +1125,7 @@ xsltDefaultSortFunction(xsltTransformContextPtr ctxt, xmlNodePtr *sorts,
comp->stype =
xsltEvalAttrValueTemplate(ctxt, sorts[j],
(const xmlChar *) "data-type",
- XSLT_NAMESPACE);
+ NULL);
if (comp->stype != NULL) {
tempstype[j] = 1;
if (xmlStrEqual(comp->stype, (const xmlChar *) "text"))
@@ -1143,7 +1144,7 @@ xsltDefaultSortFunction(xsltTransformContextPtr ctxt, xmlNodePtr *sorts,
if ((comp->order == NULL) && (comp->has_order != 0)) {
comp->order = xsltEvalAttrValueTemplate(ctxt, sorts[j],
(const xmlChar *) "order",
- XSLT_NAMESPACE);
+ NULL);
if (comp->order != NULL) {
temporder[j] = 1;
if (xmlStrEqual(comp->order, (const xmlChar *) "ascending"))
@@ -1159,6 +1160,17 @@ xsltDefaultSortFunction(xsltTransformContextPtr ctxt, xmlNodePtr *sorts,
}
}
}
+ templang[j] = 0;
+ if ((comp->lang == NULL) && (comp->has_lang != 0)) {
+ xmlChar *lang = xsltEvalAttrValueTemplate(ctxt, sorts[j],
+ (xmlChar *) "lang",
+ NULL);
+ if (lang != NULL) {
+ templang[j] = 1;
+ comp->locale = xsltNewLocale(lang);
+ xmlFree(lang);
+ }
+ }
}
len = list->nodeNr;
@@ -1173,7 +1185,7 @@ xsltDefaultSortFunction(xsltTransformContextPtr ctxt, xmlNodePtr *sorts,
descending = comp->descending;
number = comp->number;
if (results == NULL)
- return;
+ goto cleanup;
/* Shell's sort of node-set */
for (incr = len / 2; incr > 0; incr /= 2) {
@@ -1315,6 +1327,7 @@ xsltDefaultSortFunction(xsltTransformContextPtr ctxt, xmlNodePtr *sorts,
}
}
+cleanup:
for (j = 0; j < nbsorts; j++) {
comp = sorts[j]->psvi;
if (tempstype[j] == 1) {
@@ -1327,6 +1340,10 @@ xsltDefaultSortFunction(xsltTransformContextPtr ctxt, xmlNodePtr *sorts,
xmlFree((void *)(comp->order));
comp->order = NULL;
}
+ if (templang[j] == 1) {
+ xsltFreeLocale(comp->locale);
+ comp->locale = (xsltLocale)0;
+ }
if (resultsTab[j] != NULL) {
for (i = 0;i < len;i++)
xmlXPathFreeObject(resultsTab[j][i]);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]