summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJason Viers <bean@beanalby.net>2012-08-16 17:41:00 +0800
committerDaniel Veillard <veillard@redhat.com>2012-08-16 17:41:00 +0800
commit5e184e7154e8aa466e988f17c8b97b65196f94bf (patch)
treee5ab5fb09a31c5d79ffe839bc7dcde792fb52443
parent2d6e741ed9a5e54d48d394060590d151a3417dd7 (diff)
downloadlibxslt-5e184e7154e8aa466e988f17c8b97b65196f94bf.tar.gz
libxslt-5e184e7154e8aa466e988f17c8b97b65196f94bf.tar.bz2
libxslt-5e184e7154e8aa466e988f17c8b97b65196f94bf.zip
document('') fails to return stylesheets parsed from memory
If an XSL stylesheet is from memory (e.g. xmlParseMemory), then xpath expressions referencing "document('')" will never return a match. When getting down into it, I understand the logic "document() is resolved relative to the XSL's location, reading from memory has no location, therefore buzz off", but the XSL spec seems to address this: http://www.w3.org/TR/xslt#document "Note that a zero-length URI reference is a reference to the document relative to which the URI reference is being resolved; thus document("") refers to the root node of the stylesheet; the tree representation of the stylesheet is exactly the same as if the XML document containing the stylesheet was the initial source document." The fact that the behavior differs in this case between fromFile & fromMemory definitely caught me off guard, and IMHO fixing that scenario is worth the one-off-ness of the fix.
-rw-r--r--libxslt/functions.c14
1 files changed, 10 insertions, 4 deletions
diff --git a/libxslt/functions.c b/libxslt/functions.c
index 01852b89..5a8eb79f 100644
--- a/libxslt/functions.c
+++ b/libxslt/functions.c
@@ -302,6 +302,8 @@ xsltDocumentFunction(xmlXPathParserContextPtr ctxt, int nargs)
if (obj->stringval == NULL) {
valuePush(ctxt, xmlXPathNewNodeSet(NULL));
} else {
+ xsltTransformContextPtr tctxt;
+ tctxt = xsltXPathGetTransformContext(ctxt);
if ((obj2 != NULL) && (obj2->nodesetval != NULL) &&
(obj2->nodesetval->nodeNr > 0) &&
IS_XSLT_REAL_NODE(obj2->nodesetval->nodeTab[0])) {
@@ -314,9 +316,6 @@ xsltDocumentFunction(xmlXPathParserContextPtr ctxt, int nargs)
}
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) &&
@@ -329,7 +328,14 @@ xsltDocumentFunction(xmlXPathParserContextPtr ctxt, int nargs)
if (base != NULL)
xmlFree(base);
if (URI == NULL) {
- valuePush(ctxt, xmlXPathNewNodeSet(NULL));
+ if ((tctxt != NULL) && (tctxt->style != NULL) &&
+ (tctxt->style->doc != NULL) &&
+ (xmlStrEqual(URI, tctxt->style->doc->URL))) {
+ /* This selects the stylesheet's doc itself. */
+ valuePush(ctxt, xmlXPathNewNodeSet((xmlNodePtr) tctxt->style->doc));
+ } else {
+ valuePush(ctxt, xmlXPathNewNodeSet(NULL));
+ }
} else {
xsltDocumentFunctionLoadDocument( ctxt, URI );
xmlFree(URI);