mirror of
https://gitlab.gnome.org/GNOME/libxslt
synced 2025-11-05 12:10:38 +03:00
fixed bug #78735 added the tests in a separate directory Daniel
* libxslt/keys.c: fixed bug #78735 * configure.in tests/Makefile.am tests/keys/*: added the tests in a separate directory Daniel
This commit is contained in:
@@ -1,3 +1,9 @@
|
|||||||
|
Mon Apr 15 14:00:12 CEST 2002 Daniel Veillard <daniel@veillard.com>
|
||||||
|
|
||||||
|
* libxslt/keys.c: fixed bug #78735
|
||||||
|
* configure.in tests/Makefile.am tests/keys/*:
|
||||||
|
added the tests in a separate directory
|
||||||
|
|
||||||
Mon Apr 15 00:01:07 CEST 2002 Daniel Veillard <daniel@veillard.com>
|
Mon Apr 15 00:01:07 CEST 2002 Daniel Veillard <daniel@veillard.com>
|
||||||
|
|
||||||
* tests/docs/Makefile.am tests/docs/bug-83.xml
|
* tests/docs/Makefile.am tests/docs/bug-83.xml
|
||||||
|
|||||||
@@ -421,6 +421,7 @@ tests/general/Makefile
|
|||||||
tests/reports/Makefile
|
tests/reports/Makefile
|
||||||
tests/extensions/Makefile
|
tests/extensions/Makefile
|
||||||
tests/namespaces/Makefile
|
tests/namespaces/Makefile
|
||||||
|
tests/keys/Makefile
|
||||||
tests/numbers/Makefile
|
tests/numbers/Makefile
|
||||||
tests/documents/Makefile
|
tests/documents/Makefile
|
||||||
tests/xmlspec/Makefile
|
tests/xmlspec/Makefile
|
||||||
|
|||||||
@@ -356,6 +356,88 @@ xsltGetKey(xsltTransformContextPtr ctxt, const xmlChar *name,
|
|||||||
return(NULL);
|
return(NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* xsltEvalXPathKeys:
|
||||||
|
* @ctxt: the XSLT transformation context
|
||||||
|
* @comp: the compiled XPath expression
|
||||||
|
*
|
||||||
|
* Process the expression using XPath to get the list of keys
|
||||||
|
*
|
||||||
|
* Returns the array of computed string value or NULL, must be deallocated
|
||||||
|
* by the caller.
|
||||||
|
*/
|
||||||
|
static xmlChar **
|
||||||
|
xsltEvalXPathKeys(xsltTransformContextPtr ctxt, xmlXPathCompExprPtr comp) {
|
||||||
|
xmlChar **ret = NULL;
|
||||||
|
xmlXPathObjectPtr res;
|
||||||
|
xmlNodePtr oldInst;
|
||||||
|
xmlNodePtr oldNode;
|
||||||
|
int oldPos, oldSize;
|
||||||
|
int oldNsNr;
|
||||||
|
xmlNsPtr *oldNamespaces;
|
||||||
|
|
||||||
|
oldInst = ctxt->inst;
|
||||||
|
oldNode = ctxt->node;
|
||||||
|
oldPos = ctxt->xpathCtxt->proximityPosition;
|
||||||
|
oldSize = ctxt->xpathCtxt->contextSize;
|
||||||
|
oldNsNr = ctxt->xpathCtxt->nsNr;
|
||||||
|
oldNamespaces = ctxt->xpathCtxt->namespaces;
|
||||||
|
|
||||||
|
ctxt->xpathCtxt->node = ctxt->node;
|
||||||
|
/* TODO: do we need to propagate the namespaces here ? */
|
||||||
|
ctxt->xpathCtxt->namespaces = NULL;
|
||||||
|
ctxt->xpathCtxt->nsNr = 0;
|
||||||
|
res = xmlXPathCompiledEval(comp, ctxt->xpathCtxt);
|
||||||
|
if (res != NULL) {
|
||||||
|
if (res->type == XPATH_NODESET) {
|
||||||
|
int len, i, j;
|
||||||
|
|
||||||
|
if (res->nodesetval != NULL)
|
||||||
|
len = res->nodesetval->nodeNr;
|
||||||
|
if (len != 0) {
|
||||||
|
ret = (xmlChar **) xmlMalloc((len + 1) * sizeof(xmlChar *));
|
||||||
|
if (ret != NULL) {
|
||||||
|
for (i = 0,j = 0;i < len;i++) {
|
||||||
|
ret[j] = xmlXPathCastNodeToString(
|
||||||
|
res->nodesetval->nodeTab[i]);
|
||||||
|
if (ret[j] != NULL)
|
||||||
|
j++;
|
||||||
|
}
|
||||||
|
ret[j] = NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (res->type != XPATH_STRING)
|
||||||
|
res = xmlXPathConvertString(res);
|
||||||
|
if (res->type == XPATH_STRING) {
|
||||||
|
ret = (xmlChar **) xmlMalloc(2 * sizeof(xmlChar *));
|
||||||
|
if (ret != NULL) {
|
||||||
|
ret[0] = res->stringval;
|
||||||
|
ret[1] = NULL;
|
||||||
|
res->stringval = NULL;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
xsltPrintErrorContext(ctxt, NULL, NULL);
|
||||||
|
xsltGenericError(xsltGenericErrorContext,
|
||||||
|
"xpath : string() function didn't return a String\n");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
xmlXPathFreeObject(res);
|
||||||
|
} else {
|
||||||
|
ctxt->state = XSLT_STATE_STOPPED;
|
||||||
|
}
|
||||||
|
#ifdef WITH_XSLT_DEBUG_TEMPLATES
|
||||||
|
xsltGenericDebug(xsltGenericDebugContext,
|
||||||
|
"xsltEvalXPathString: returns %s\n", ret);
|
||||||
|
#endif
|
||||||
|
ctxt->inst = oldInst;
|
||||||
|
ctxt->node = oldNode;
|
||||||
|
ctxt->xpathCtxt->contextSize = oldSize;
|
||||||
|
ctxt->xpathCtxt->proximityPosition = oldPos;
|
||||||
|
ctxt->xpathCtxt->nsNr = oldNsNr;
|
||||||
|
ctxt->xpathCtxt->namespaces = oldNamespaces;
|
||||||
|
return(ret);
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
* xsltInitCtxtKey:
|
* xsltInitCtxtKey:
|
||||||
* @ctxt: an XSLT transformation context
|
* @ctxt: an XSLT transformation context
|
||||||
@@ -370,7 +452,7 @@ xsltInitCtxtKey(xsltTransformContextPtr ctxt, xsltDocumentPtr doc,
|
|||||||
int i;
|
int i;
|
||||||
xmlNodeSetPtr nodelist = NULL, keylist;
|
xmlNodeSetPtr nodelist = NULL, keylist;
|
||||||
xmlXPathObjectPtr res = NULL;
|
xmlXPathObjectPtr res = NULL;
|
||||||
xmlChar *str;
|
xmlChar *str, **list;
|
||||||
xsltKeyTablePtr table;
|
xsltKeyTablePtr table;
|
||||||
int oldPos, oldSize;
|
int oldPos, oldSize;
|
||||||
xmlNodePtr oldInst;
|
xmlNodePtr oldInst;
|
||||||
@@ -447,8 +529,13 @@ xsltInitCtxtKey(xsltTransformContextPtr ctxt, xsltDocumentPtr doc,
|
|||||||
for (i = 0;i < nodelist->nodeNr;i++) {
|
for (i = 0;i < nodelist->nodeNr;i++) {
|
||||||
if (IS_XSLT_REAL_NODE(nodelist->nodeTab[i])) {
|
if (IS_XSLT_REAL_NODE(nodelist->nodeTab[i])) {
|
||||||
ctxt->node = nodelist->nodeTab[i];
|
ctxt->node = nodelist->nodeTab[i];
|
||||||
str = xsltEvalXPathString(ctxt, keyd->usecomp);
|
|
||||||
if (str != NULL) {
|
list = xsltEvalXPathKeys(ctxt, keyd->usecomp);
|
||||||
|
if (list != NULL) {
|
||||||
|
int index = 0;
|
||||||
|
|
||||||
|
str = list[index++];
|
||||||
|
while (str != NULL) {
|
||||||
#ifdef WITH_XSLT_DEBUG_KEYS
|
#ifdef WITH_XSLT_DEBUG_KEYS
|
||||||
xsltGenericDebug(xsltGenericDebugContext,
|
xsltGenericDebug(xsltGenericDebugContext,
|
||||||
"xsl:key : node associated to(%s,%s)\n",
|
"xsl:key : node associated to(%s,%s)\n",
|
||||||
@@ -463,10 +550,13 @@ xsltInitCtxtKey(xsltTransformContextPtr ctxt, xsltDocumentPtr doc,
|
|||||||
}
|
}
|
||||||
nodelist->nodeTab[i]->_private = keyd;
|
nodelist->nodeTab[i]->_private = keyd;
|
||||||
xmlFree(str);
|
xmlFree(str);
|
||||||
|
str = list[index++];
|
||||||
|
}
|
||||||
|
xmlFree(list);
|
||||||
#ifdef WITH_XSLT_DEBUG_KEYS
|
#ifdef WITH_XSLT_DEBUG_KEYS
|
||||||
} else {
|
} else {
|
||||||
xsltGenericDebug(xsltGenericDebugContext,
|
xsltGenericDebug(xsltGenericDebugContext,
|
||||||
"xsl:key : use %s failed to return a string\n",
|
"xsl:key : use %s failed to return strings\n",
|
||||||
keyd->use);
|
keyd->use);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
## Process this file with automake to produce Makefile.in
|
## Process this file with automake to produce Makefile.in
|
||||||
|
|
||||||
SUBDIRS=docs REC1 REC2 REC general namespaces numbers documents \
|
SUBDIRS=docs REC1 REC2 REC general namespaces keys numbers documents \
|
||||||
extensions reports xmlspec multiple XSLTMark docbook exslt
|
extensions reports xmlspec multiple XSLTMark docbook exslt
|
||||||
|
|
||||||
all:
|
all:
|
||||||
|
|||||||
22
tests/keys/Makefile.am
Normal file
22
tests/keys/Makefile.am
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
## Process this file with automake to produce Makefile.in
|
||||||
|
|
||||||
|
$(top_builddir)/xsltproc/xsltproc:
|
||||||
|
@(cd ../../xsltproc ; $(MAKE) xsltproc)
|
||||||
|
|
||||||
|
EXTRA_DIST = dates.xml month.xml month.xsl month.out
|
||||||
|
|
||||||
|
all:
|
||||||
|
|
||||||
|
valgrind:
|
||||||
|
@echo '## Running the regression tests under Valgrind'
|
||||||
|
$(MAKE) CHECKER='valgrind -q' tests
|
||||||
|
|
||||||
|
test tests: $(top_builddir)/xsltproc/xsltproc
|
||||||
|
@(echo > .memdump)
|
||||||
|
@($(CHECKER) $(top_builddir)/xsltproc/xsltproc $(srcdir)/month.xsl $(srcdir)/dates.xml > month.res ; \
|
||||||
|
if [ -r $(srcdir)/month.out ] ; \
|
||||||
|
then diff $(srcdir)/month.out month.res ; \
|
||||||
|
else mv month.res $(srcdir)/month.out ; fi ; \
|
||||||
|
grep "MORY ALLO" .memdump | grep -v "MEMORY ALLOCATED : 0" || true;\
|
||||||
|
rm -f month.res)
|
||||||
|
|
||||||
7
tests/keys/dates.xml
Normal file
7
tests/keys/dates.xml
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
<?xml version="1.0" encoding="iso-8859-1"?>
|
||||||
|
<dates>
|
||||||
|
<month>12</month>
|
||||||
|
<month>Dec</month>
|
||||||
|
<month>December</month>
|
||||||
|
<month>dismember</month>
|
||||||
|
</dates>
|
||||||
7
tests/keys/month.out
Normal file
7
tests/keys/month.out
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
<?xml version="1.0" encoding="iso-8859-1"?>
|
||||||
|
<dates>
|
||||||
|
<month>December</month>
|
||||||
|
<month>December</month>
|
||||||
|
<month>December</month>
|
||||||
|
<month></month>
|
||||||
|
</dates>
|
||||||
9
tests/keys/month.xml
Normal file
9
tests/keys/month.xml
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
<?xml version="1.0" encoding="iso-8859-1"?>
|
||||||
|
<list>
|
||||||
|
<month>
|
||||||
|
<alias>December</alias>
|
||||||
|
<alias>12</alias>
|
||||||
|
<alias>Dec</alias>
|
||||||
|
<alias>DEC</alias>
|
||||||
|
</month>
|
||||||
|
</list>
|
||||||
19
tests/keys/month.xsl
Normal file
19
tests/keys/month.xsl
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
<?xml version="1.0" encoding="iso-8859-1"?>
|
||||||
|
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
|
||||||
|
<xsl:output indent="no" version="1.0" encoding="iso-8859-1"/>
|
||||||
|
<xsl:key name="monthlist" match="/list/month" use="./alias"/>
|
||||||
|
<xsl:template match="month">
|
||||||
|
<month>
|
||||||
|
<xsl:variable name="value" select="."/>
|
||||||
|
<xsl:for-each select="document('month.xml')">
|
||||||
|
<xsl:value-of select="key('monthlist', $value)/alias[1]"/>
|
||||||
|
</xsl:for-each>
|
||||||
|
</month>
|
||||||
|
</xsl:template>
|
||||||
|
<xsl:template match="*">
|
||||||
|
<xsl:copy>
|
||||||
|
<xsl:copy-of select="@*"/>
|
||||||
|
<xsl:apply-templates/>
|
||||||
|
</xsl:copy>
|
||||||
|
</xsl:template>
|
||||||
|
</xsl:stylesheet>
|
||||||
Reference in New Issue
Block a user