diff options
author | Nick Wellnhofer <wellnhofer@aevum.de> | 2020-12-19 16:35:22 +0100 |
---|---|---|
committer | Nick Wellnhofer <wellnhofer@aevum.de> | 2020-12-19 16:35:22 +0100 |
commit | 3df643af3332f5caf8e1f1be06d5b44f77c13ed7 (patch) | |
tree | 4bd7d8a570850481c9a7f660c6728613e579dbcb | |
parent | 7fd30eba2f0f96be90a0741e051099d55970bded (diff) | |
download | libxslt-3df643af3332f5caf8e1f1be06d5b44f77c13ed7.tar.gz |
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.
-rw-r--r-- | libxslt/xsltutils.c | 25 |
1 files 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]); |