mirror of
https://gitlab.gnome.org/GNOME/libxslt
synced 2026-01-07 21:58:22 +03:00
fixed document('') as pointed by Eric van der Vlist added the specific
* libxslt/documents.c libxslt/functions.c libxslt/xsltInternals.h:
fixed document('') as pointed by Eric van der Vlist
* tests/docs/Makefile.am tests/docs/bug-86.xml
tests/general/Makefile.am tests/general/bug-86.*: added the
specific example in the regression tests
Daniel
This commit is contained in:
@@ -1,3 +1,11 @@
|
||||
Wed Jun 19 13:43:00 CEST 2002 Daniel Veillard <daniel@veillard.com>
|
||||
|
||||
* libxslt/documents.c libxslt/functions.c libxslt/xsltInternals.h:
|
||||
fixed document('') as pointed by Eric van der Vlist
|
||||
* tests/docs/Makefile.am tests/docs/bug-86.xml
|
||||
tests/general/Makefile.am tests/general/bug-86.*: added the
|
||||
specific example in the regression tests
|
||||
|
||||
Sat Jun 15 15:44:58 CEST 2002 Daniel Veillard <daniel@veillard.com>
|
||||
|
||||
* libxslt/numbers.c libxslt/numbersInternals.h: applied a
|
||||
|
||||
@@ -26,6 +26,8 @@
|
||||
#include <libxml/xinclude.h>
|
||||
#endif
|
||||
|
||||
#define WITH_XSLT_DEBUG_DOCUMENTS
|
||||
|
||||
#ifdef WITH_XSLT_DEBUG
|
||||
#define WITH_XSLT_DEBUG_DOCUMENTS
|
||||
#endif
|
||||
@@ -131,6 +133,15 @@ xsltFreeDocuments(xsltTransformContextPtr ctxt) {
|
||||
xmlFreeDoc(doc->doc);
|
||||
xmlFree(doc);
|
||||
}
|
||||
cur = ctxt->styleList;
|
||||
while (cur != NULL) {
|
||||
doc = cur;
|
||||
cur = cur->next;
|
||||
xsltFreeDocumentKeys(doc);
|
||||
if (!doc->main)
|
||||
xmlFreeDoc(doc->doc);
|
||||
xmlFree(doc);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -139,7 +150,8 @@ xsltFreeDocuments(xsltTransformContextPtr ctxt) {
|
||||
* @ctxt: an XSLT transformation context
|
||||
* @URI: the computed URI of the document
|
||||
*
|
||||
* Try to load a document within the XSLT transformation context
|
||||
* Try to load a document (not a stylesheet)
|
||||
* within the XSLT transformation context
|
||||
*
|
||||
* Returns the new xsltDocumentPtr or NULL in case of error
|
||||
*/
|
||||
@@ -191,7 +203,7 @@ xsltLoadDocument(xsltTransformContextPtr ctxt, const xmlChar *URI) {
|
||||
* @style: an XSLT style sheet
|
||||
* @URI: the computed URI of the document
|
||||
*
|
||||
* Try to load a document within the XSLT transformation context
|
||||
* Try to load a stylesheet document within the XSLT transformation context
|
||||
*
|
||||
* Returns the new xsltDocumentPtr or NULL in case of error
|
||||
*/
|
||||
|
||||
@@ -106,147 +106,149 @@ xsltXPathFunctionLookup (xmlXPathContextPtr ctxt,
|
||||
* node-set document(object, node-set?)
|
||||
*/
|
||||
void
|
||||
xsltDocumentFunction(xmlXPathParserContextPtr ctxt, int nargs){
|
||||
xsltDocumentFunction(xmlXPathParserContextPtr ctxt, int nargs)
|
||||
{
|
||||
xsltDocumentPtr doc;
|
||||
xmlXPathObjectPtr obj, obj2 = NULL;
|
||||
xmlChar *base = NULL, *URI;
|
||||
|
||||
|
||||
if ((nargs < 1) || (nargs > 2)) {
|
||||
xsltPrintErrorContext(xsltXPathGetTransformContext(ctxt), NULL, NULL);
|
||||
xsltPrintErrorContext(xsltXPathGetTransformContext(ctxt), NULL,
|
||||
NULL);
|
||||
xsltGenericError(xsltGenericErrorContext,
|
||||
"document() : invalid number of args %d\n", nargs);
|
||||
ctxt->error = XPATH_INVALID_ARITY;
|
||||
return;
|
||||
"document() : invalid number of args %d\n",
|
||||
nargs);
|
||||
ctxt->error = XPATH_INVALID_ARITY;
|
||||
return;
|
||||
}
|
||||
if (ctxt->value == NULL) {
|
||||
xsltPrintErrorContext(xsltXPathGetTransformContext(ctxt), NULL, NULL);
|
||||
xsltGenericError(xsltGenericErrorContext,
|
||||
"document() : invalid arg value\n");
|
||||
ctxt->error = XPATH_INVALID_TYPE;
|
||||
return;
|
||||
xsltPrintErrorContext(xsltXPathGetTransformContext(ctxt), NULL,
|
||||
NULL);
|
||||
xsltGenericError(xsltGenericErrorContext,
|
||||
"document() : invalid arg value\n");
|
||||
ctxt->error = XPATH_INVALID_TYPE;
|
||||
return;
|
||||
}
|
||||
|
||||
if (nargs == 2) {
|
||||
if (ctxt->value->type != XPATH_NODESET) {
|
||||
xsltPrintErrorContext(xsltXPathGetTransformContext(ctxt),
|
||||
NULL, NULL);
|
||||
xsltGenericError(xsltGenericErrorContext,
|
||||
"document() : invalid arg expecting a nodeset\n");
|
||||
ctxt->error = XPATH_INVALID_TYPE;
|
||||
return;
|
||||
}
|
||||
if (ctxt->value->type != XPATH_NODESET) {
|
||||
xsltPrintErrorContext(xsltXPathGetTransformContext(ctxt),
|
||||
NULL, NULL);
|
||||
xsltGenericError(xsltGenericErrorContext,
|
||||
"document() : invalid arg expecting a nodeset\n");
|
||||
ctxt->error = XPATH_INVALID_TYPE;
|
||||
return;
|
||||
}
|
||||
|
||||
obj2 = valuePop(ctxt);
|
||||
obj2 = valuePop(ctxt);
|
||||
}
|
||||
|
||||
if (ctxt->value->type == XPATH_NODESET) {
|
||||
int i;
|
||||
xmlXPathObjectPtr newobj, ret;
|
||||
int i;
|
||||
xmlXPathObjectPtr newobj, ret;
|
||||
|
||||
obj = valuePop(ctxt);
|
||||
ret = xmlXPathNewNodeSet(NULL);
|
||||
obj = valuePop(ctxt);
|
||||
ret = xmlXPathNewNodeSet(NULL);
|
||||
|
||||
if (obj->nodesetval) {
|
||||
for (i = 0; i < obj->nodesetval->nodeNr; i++) {
|
||||
valuePush(ctxt,
|
||||
xmlXPathNewNodeSet(obj->nodesetval->nodeTab[i]));
|
||||
xmlXPathStringFunction(ctxt, 1);
|
||||
if (nargs == 2) {
|
||||
valuePush(ctxt, xmlXPathObjectCopy(obj2));
|
||||
} else {
|
||||
valuePush(ctxt,
|
||||
xmlXPathNewNodeSet(obj->nodesetval->nodeTab[i]));
|
||||
}
|
||||
xsltDocumentFunction(ctxt, 2);
|
||||
newobj = valuePop(ctxt);
|
||||
ret->nodesetval = xmlXPathNodeSetMerge(ret->nodesetval,
|
||||
newobj->nodesetval);
|
||||
xmlXPathFreeObject(newobj);
|
||||
}
|
||||
}
|
||||
if (obj->nodesetval) {
|
||||
for (i = 0; i < obj->nodesetval->nodeNr; i++) {
|
||||
valuePush(ctxt,
|
||||
xmlXPathNewNodeSet(obj->nodesetval->nodeTab[i]));
|
||||
xmlXPathStringFunction(ctxt, 1);
|
||||
if (nargs == 2) {
|
||||
valuePush(ctxt, xmlXPathObjectCopy(obj2));
|
||||
} else {
|
||||
valuePush(ctxt,
|
||||
xmlXPathNewNodeSet(obj->nodesetval->
|
||||
nodeTab[i]));
|
||||
}
|
||||
xsltDocumentFunction(ctxt, 2);
|
||||
newobj = valuePop(ctxt);
|
||||
ret->nodesetval = xmlXPathNodeSetMerge(ret->nodesetval,
|
||||
newobj->nodesetval);
|
||||
xmlXPathFreeObject(newobj);
|
||||
}
|
||||
}
|
||||
|
||||
xmlXPathFreeObject(obj);
|
||||
if (obj2 != NULL)
|
||||
xmlXPathFreeObject(obj2);
|
||||
valuePush(ctxt, ret);
|
||||
return;
|
||||
xmlXPathFreeObject(obj);
|
||||
if (obj2 != NULL)
|
||||
xmlXPathFreeObject(obj2);
|
||||
valuePush(ctxt, ret);
|
||||
return;
|
||||
}
|
||||
/*
|
||||
* Make sure it's converted to a string
|
||||
*/
|
||||
xmlXPathStringFunction(ctxt, 1);
|
||||
if (ctxt->value->type != XPATH_STRING) {
|
||||
xsltPrintErrorContext(xsltXPathGetTransformContext(ctxt), NULL, NULL);
|
||||
xsltGenericError(xsltGenericErrorContext,
|
||||
"document() : invalid arg expecting a string\n");
|
||||
ctxt->error = XPATH_INVALID_TYPE;
|
||||
if (obj2 != NULL)
|
||||
xmlXPathFreeObject(obj2);
|
||||
return;
|
||||
xsltPrintErrorContext(xsltXPathGetTransformContext(ctxt), NULL,
|
||||
NULL);
|
||||
xsltGenericError(xsltGenericErrorContext,
|
||||
"document() : invalid arg expecting a string\n");
|
||||
ctxt->error = XPATH_INVALID_TYPE;
|
||||
if (obj2 != NULL)
|
||||
xmlXPathFreeObject(obj2);
|
||||
return;
|
||||
}
|
||||
obj = valuePop(ctxt);
|
||||
if (obj->stringval == NULL) {
|
||||
valuePush(ctxt, xmlXPathNewNodeSet(NULL));
|
||||
valuePush(ctxt, xmlXPathNewNodeSet(NULL));
|
||||
} else {
|
||||
if ((obj2 != NULL) && (obj2->nodesetval != NULL) &&
|
||||
(obj2->nodesetval->nodeNr > 0) &&
|
||||
IS_XSLT_REAL_NODE(obj2->nodesetval->nodeTab[0])) {
|
||||
xmlNodePtr target;
|
||||
if ((obj2 != NULL) && (obj2->nodesetval != NULL) &&
|
||||
(obj2->nodesetval->nodeNr > 0) &&
|
||||
IS_XSLT_REAL_NODE(obj2->nodesetval->nodeTab[0])) {
|
||||
xmlNodePtr target;
|
||||
|
||||
target = obj2->nodesetval->nodeTab[0];
|
||||
if (target->type == XML_ATTRIBUTE_NODE) {
|
||||
target = ((xmlAttrPtr) target)->parent;
|
||||
}
|
||||
base = xmlNodeGetBase(target->doc, target);
|
||||
} else {
|
||||
xsltTransformContextPtr tctxt;
|
||||
|
||||
tctxt = xsltXPathGetTransformContext(ctxt);
|
||||
if ((tctxt != NULL) && (tctxt->inst != NULL)) {
|
||||
base = xmlNodeGetBase(tctxt->inst->doc, tctxt->inst);
|
||||
} else if ((tctxt != NULL) && (tctxt->style != NULL) &&
|
||||
(tctxt->style->doc != NULL)) {
|
||||
base = xmlNodeGetBase(tctxt->style->doc,
|
||||
(xmlNodePtr) tctxt->style->doc);
|
||||
}
|
||||
}
|
||||
URI = xmlBuildURI(obj->stringval, base);
|
||||
if (base != NULL)
|
||||
xmlFree(base);
|
||||
target = obj2->nodesetval->nodeTab[0];
|
||||
if (target->type == XML_ATTRIBUTE_NODE) {
|
||||
target = ((xmlAttrPtr) target)->parent;
|
||||
}
|
||||
base = xmlNodeGetBase(target->doc, target);
|
||||
} else {
|
||||
xsltTransformContextPtr tctxt;
|
||||
|
||||
tctxt = xsltXPathGetTransformContext(ctxt);
|
||||
if ((tctxt != NULL) && (tctxt->inst != NULL)) {
|
||||
base = xmlNodeGetBase(tctxt->inst->doc, tctxt->inst);
|
||||
} else if ((tctxt != NULL) && (tctxt->style != NULL) &&
|
||||
(tctxt->style->doc != NULL)) {
|
||||
base = xmlNodeGetBase(tctxt->style->doc,
|
||||
(xmlNodePtr) tctxt->style->doc);
|
||||
}
|
||||
}
|
||||
URI = xmlBuildURI(obj->stringval, base);
|
||||
if (base != NULL)
|
||||
xmlFree(base);
|
||||
if (URI == NULL) {
|
||||
valuePush(ctxt, xmlXPathNewNodeSet(NULL));
|
||||
} else {
|
||||
xsltTransformContextPtr tctxt;
|
||||
valuePush(ctxt, xmlXPathNewNodeSet(NULL));
|
||||
} else {
|
||||
xsltTransformContextPtr tctxt;
|
||||
|
||||
tctxt = xsltXPathGetTransformContext(ctxt);
|
||||
if (tctxt == NULL) {
|
||||
xsltPrintErrorContext(xsltXPathGetTransformContext(ctxt),
|
||||
NULL, NULL);
|
||||
xsltGenericError(xsltGenericErrorContext,
|
||||
"document() : internal error tctxt == NULL\n");
|
||||
valuePush(ctxt, xmlXPathNewNodeSet(NULL));
|
||||
} else {
|
||||
if (xmlStrEqual(tctxt->style->doc->URL, URI)) {
|
||||
valuePush(ctxt, xmlXPathNewNodeSet((xmlNodePtr)tctxt->style->doc));
|
||||
}
|
||||
tctxt = xsltXPathGetTransformContext(ctxt);
|
||||
if (tctxt == NULL) {
|
||||
xsltPrintErrorContext(xsltXPathGetTransformContext(ctxt),
|
||||
NULL, NULL);
|
||||
xsltGenericError(xsltGenericErrorContext,
|
||||
"document() : internal error tctxt == NULL\n");
|
||||
valuePush(ctxt, xmlXPathNewNodeSet(NULL));
|
||||
} else {
|
||||
doc = xsltLoadDocument(tctxt, URI);
|
||||
if (doc == NULL)
|
||||
valuePush(ctxt, xmlXPathNewNodeSet(NULL));
|
||||
else {
|
||||
doc = xsltLoadDocument(tctxt, URI);
|
||||
if (doc == NULL)
|
||||
valuePush(ctxt, xmlXPathNewNodeSet(NULL));
|
||||
else {
|
||||
/* TODO: use XPointer of HTML location for fragment ID */
|
||||
/* pbm #xxx can lead to location sets, not nodesets :-) */
|
||||
valuePush(ctxt, xmlXPathNewNodeSet((xmlNodePtr) doc->doc));
|
||||
}
|
||||
/* TODO: use XPointer of HTML location for fragment ID */
|
||||
/* pbm #xxx can lead to location sets, not nodesets :-) */
|
||||
valuePush(ctxt,
|
||||
xmlXPathNewNodeSet((xmlNodePtr) doc->doc));
|
||||
}
|
||||
}
|
||||
xmlFree(URI);
|
||||
}
|
||||
}
|
||||
xmlFree(URI);
|
||||
}
|
||||
}
|
||||
xmlXPathFreeObject(obj);
|
||||
if (obj2 != NULL)
|
||||
xmlXPathFreeObject(obj2);
|
||||
xmlXPathFreeObject(obj2);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -451,6 +451,8 @@ struct _xsltTransformContext {
|
||||
int extrasNr; /* the number of extras used */
|
||||
int extrasMax; /* the number of extras allocated */
|
||||
xsltRuntimeExtraPtr extras; /* extra per runtime informations */
|
||||
|
||||
xsltDocumentPtr styleList; /* the stylesheet docs list */
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
@@ -85,6 +85,7 @@ EXTRA_DIST = \
|
||||
bug-82.xml \
|
||||
bug-83.xml \
|
||||
bug-84.xml \
|
||||
bug-86.xml \
|
||||
character.xml \
|
||||
array.xml \
|
||||
items.xml
|
||||
|
||||
7
tests/docs/bug-86.xml
Normal file
7
tests/docs/bug-86.xml
Normal file
@@ -0,0 +1,7 @@
|
||||
<?xml version="1.0" encoding="iso-8859-1"?>
|
||||
<xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
|
||||
xmlns:vdv="http://eric.van-der-vlist.com/tmpns" version="1.0">
|
||||
<xsl:template match="/">
|
||||
<xsl:copy-of select="document('')/xsl:transform"/>
|
||||
</xsl:template>
|
||||
</xsl:transform>
|
||||
@@ -88,6 +88,7 @@ EXTRA_DIST = \
|
||||
bug-82.out bug-82.xsl \
|
||||
bug-83.out bug-83.xsl \
|
||||
bug-84.out bug-84.xsl \
|
||||
bug-86.out bug-86.xsl \
|
||||
character.out character.xsl \
|
||||
character2.out character2.xsl \
|
||||
itemschoose.out itemschoose.xsl \
|
||||
|
||||
6
tests/general/bug-86.out
Normal file
6
tests/general/bug-86.out
Normal file
@@ -0,0 +1,6 @@
|
||||
<?xml version="1.0"?>
|
||||
<xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:vdv="http://eric.van-der-vlist.com/tmpns" version="1.0">
|
||||
<xsl:template match="/">
|
||||
<xsl:copy-of select="document('')/xsl:transform"/>
|
||||
</xsl:template>
|
||||
</xsl:transform>
|
||||
7
tests/general/bug-86.xsl
Normal file
7
tests/general/bug-86.xsl
Normal file
@@ -0,0 +1,7 @@
|
||||
<?xml version="1.0" encoding="iso-8859-1"?>
|
||||
<xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
|
||||
xmlns:vdv="http://eric.van-der-vlist.com/tmpns" version="1.0">
|
||||
<xsl:template match="/">
|
||||
<xsl:copy-of select="document('')/xsl:transform"/>
|
||||
</xsl:template>
|
||||
</xsl:transform>
|
||||
Reference in New Issue
Block a user