mirror of
https://gitlab.gnome.org/GNOME/libxslt
synced 2025-11-02 13:33:20 +03:00
cleaned up the code w.r.t. handling of 'non-standard' libxml element like
* libxslt/functions.c libxslt/keys.c libxslt/transform.c libxslt/xsltutils.h: cleaned up the code w.r.t. handling of 'non-standard' libxml element like namespace nodes. * tests/docs/Makefile.am tests/docs/bug-54.xml tests/general/Makefile.am tests/general/bug-54.*: added a specific example in the regression tests Daniel
This commit is contained in:
@@ -1,3 +1,12 @@
|
||||
Sun Aug 12 21:53:13 CEST 2001 Daniel Veillard <daniel@veillard.com>
|
||||
|
||||
* libxslt/functions.c libxslt/keys.c libxslt/transform.c
|
||||
libxslt/xsltutils.h: cleaned up the code w.r.t. handling
|
||||
of 'non-standard' libxml element like namespace nodes.
|
||||
* tests/docs/Makefile.am tests/docs/bug-54.xml
|
||||
tests/general/Makefile.am tests/general/bug-54.*: added a
|
||||
specific example in the regression tests
|
||||
|
||||
Wed Aug 8 22:57:05 CEST 2001 Daniel Veillard <daniel@veillard.com>
|
||||
|
||||
* HACKING: added John Fleck right to commit in the doc subdir
|
||||
|
||||
@@ -189,7 +189,8 @@ xsltDocumentFunction(xmlXPathParserContextPtr ctxt, int nargs){
|
||||
valuePush(ctxt, xmlXPathNewNodeSet(NULL));
|
||||
} else {
|
||||
if ((obj2 != NULL) && (obj2->nodesetval != NULL) &&
|
||||
(obj2->nodesetval->nodeNr > 0)) {
|
||||
(obj2->nodesetval->nodeNr > 0) &&
|
||||
IS_XSLT_REAL_NODE(obj2->nodesetval->nodeTab[0])) {
|
||||
xmlNodePtr target;
|
||||
|
||||
target = obj2->nodesetval->nodeTab[0];
|
||||
|
||||
@@ -405,29 +405,31 @@ xsltInitCtxtKey(xsltTransformContextPtr ctxt, xsltDocumentPtr doc,
|
||||
goto error;
|
||||
|
||||
for (i = 0;i < nodelist->nodeNr;i++) {
|
||||
ctxt->node = nodelist->nodeTab[i];
|
||||
str = xsltEvalXPathString(ctxt, keyd->usecomp);
|
||||
if (str != NULL) {
|
||||
if (IS_XSLT_REAL_NODE(nodelist->nodeTab[i])) {
|
||||
ctxt->node = nodelist->nodeTab[i];
|
||||
str = xsltEvalXPathString(ctxt, keyd->usecomp);
|
||||
if (str != NULL) {
|
||||
#ifdef WITH_XSLT_DEBUG_KEYS
|
||||
xsltGenericDebug(xsltGenericDebugContext,
|
||||
"xsl:key : node associated to(%s,%s)\n",
|
||||
keyd->name, str);
|
||||
xsltGenericDebug(xsltGenericDebugContext,
|
||||
"xsl:key : node associated to(%s,%s)\n",
|
||||
keyd->name, str);
|
||||
#endif
|
||||
keylist = xmlHashLookup(table->keys, str);
|
||||
if (keylist == NULL) {
|
||||
keylist = xmlXPathNodeSetCreate(nodelist->nodeTab[i]);
|
||||
xmlHashAddEntry(table->keys, str, keylist);
|
||||
keylist = xmlHashLookup(table->keys, str);
|
||||
if (keylist == NULL) {
|
||||
keylist = xmlXPathNodeSetCreate(nodelist->nodeTab[i]);
|
||||
xmlHashAddEntry(table->keys, str, keylist);
|
||||
} else {
|
||||
xmlXPathNodeSetAdd(keylist, nodelist->nodeTab[i]);
|
||||
}
|
||||
nodelist->nodeTab[i]->_private = keyd;
|
||||
xmlFree(str);
|
||||
#ifdef WITH_XSLT_DEBUG_KEYS
|
||||
} else {
|
||||
xmlXPathNodeSetAdd(keylist, nodelist->nodeTab[i]);
|
||||
}
|
||||
nodelist->nodeTab[i]->_private = keyd;
|
||||
xmlFree(str);
|
||||
#ifdef WITH_XSLT_DEBUG_KEYS
|
||||
} else {
|
||||
xsltGenericDebug(xsltGenericDebugContext,
|
||||
"xsl:key : use %s failed to return a string\n",
|
||||
keyd->use);
|
||||
xsltGenericDebug(xsltGenericDebugContext,
|
||||
"xsl:key : use %s failed to return a string\n",
|
||||
keyd->use);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -586,6 +586,8 @@ xsltCopyTree(xsltTransformContextPtr ctxt, xmlNodePtr node,
|
||||
return((xmlNodePtr)
|
||||
xsltCopyProp(ctxt, insert, (xmlAttrPtr) node));
|
||||
case XML_NAMESPACE_DECL:
|
||||
if (insert->type != XML_ELEMENT_NODE)
|
||||
return(NULL);
|
||||
return((xmlNodePtr)
|
||||
xsltCopyNamespaceList(ctxt, insert, (xmlNsPtr) node));
|
||||
|
||||
@@ -912,7 +914,8 @@ xsltProcessOneNode(xsltTransformContextPtr ctxt, xmlNodePtr node,
|
||||
/*
|
||||
* Cleanup children empty nodes if asked for
|
||||
*/
|
||||
if ((node->children != NULL) &&
|
||||
if ((IS_XSLT_REAL_NODE(node)) &&
|
||||
(node->children != NULL) &&
|
||||
(xsltFindElemSpaceHandling(ctxt, node))) {
|
||||
xmlNodePtr delete = NULL, cur = node->children;
|
||||
|
||||
@@ -2260,7 +2263,8 @@ xsltCopyOf(xsltTransformContextPtr ctxt, xmlNodePtr node,
|
||||
#endif
|
||||
list = res->nodesetval;
|
||||
if ((list != NULL) && (list->nodeTab != NULL) &&
|
||||
(list->nodeTab[0] != NULL)) {
|
||||
(list->nodeTab[0] != NULL) &&
|
||||
(IS_XSLT_REAL_NODE(list->nodeTab[0]))) {
|
||||
xsltCopyTreeList(ctxt, list->nodeTab[0]->children,
|
||||
ctxt->insert);
|
||||
}
|
||||
@@ -2682,9 +2686,10 @@ xsltApplyTemplates(xsltTransformContextPtr ctxt, xmlNodePtr node,
|
||||
ctxt->node = list->nodeTab[i];
|
||||
ctxt->xpathCtxt->proximityPosition = i + 1;
|
||||
/* For a 'select' nodeset, need to check if document has changed */
|
||||
if ( (list->nodeTab[i]->doc!=NULL) &&
|
||||
(list->nodeTab[i]->doc->doc!=NULL) &&
|
||||
(list->nodeTab[i]->doc->doc)!=ctxt->xpathCtxt->doc) {
|
||||
if ((IS_XSLT_REAL_NODE(list->nodeTab[i])) &&
|
||||
(list->nodeTab[i]->doc!=NULL) &&
|
||||
(list->nodeTab[i]->doc->doc!=NULL) &&
|
||||
(list->nodeTab[i]->doc->doc)!=ctxt->xpathCtxt->doc) {
|
||||
/* The nodeset is from another document, so must change */
|
||||
ctxt->xpathCtxt->doc=list->nodeTab[i]->doc->doc;
|
||||
if ((ctxt->document =
|
||||
@@ -2696,7 +2701,7 @@ xsltApplyTemplates(xsltTransformContextPtr ctxt, xmlNodePtr node,
|
||||
}
|
||||
ctxt->xpathCtxt->node = list->nodeTab[i];
|
||||
#ifdef WITH_XSLT_DEBUG_PROCESS
|
||||
xsltGenericDebug(xsltGenericDebugContext,
|
||||
xsltGenericDebug(xsltGenericDebugContext,
|
||||
"xsltApplyTemplates: Changing document - context doc %s, xpathdoc %s\n",
|
||||
ctxt->document->doc->URL, ctxt->xpathCtxt->doc->URL);
|
||||
#endif
|
||||
@@ -3016,9 +3021,10 @@ xsltForEach(xsltTransformContextPtr ctxt, xmlNodePtr node,
|
||||
ctxt->node = list->nodeTab[i];
|
||||
ctxt->xpathCtxt->proximityPosition = i + 1;
|
||||
/* For a 'select' nodeset, need to check if document has changed */
|
||||
if ( (list->nodeTab[i]->doc!=NULL) &&
|
||||
(list->nodeTab[i]->doc->doc!=NULL) &&
|
||||
(list->nodeTab[i]->doc->doc)!=ctxt->xpathCtxt->doc) {
|
||||
if ((IS_XSLT_REAL_NODE(list->nodeTab[i])) &&
|
||||
(list->nodeTab[i]->doc!=NULL) &&
|
||||
(list->nodeTab[i]->doc->doc!=NULL) &&
|
||||
(list->nodeTab[i]->doc->doc)!=ctxt->xpathCtxt->doc) {
|
||||
/* The nodeset is from another document, so must change */
|
||||
ctxt->xpathCtxt->doc=list->nodeTab[i]->doc->doc;
|
||||
if ((ctxt->document =
|
||||
|
||||
@@ -60,6 +60,30 @@ extern "C" {
|
||||
#define IS_XSLT_NAME(n, val) \
|
||||
(xmlStrEqual((n)->name, (const xmlChar *) (val)))
|
||||
|
||||
/**
|
||||
* IS_XSLT_REAL_NODE:
|
||||
*
|
||||
* check that a node is a 'real' one: document, element, text or attribute
|
||||
*/
|
||||
#ifdef LIBXML_DOCB_ENABLED
|
||||
#define IS_XSLT_REAL_NODE(n) \
|
||||
(((n) != NULL) && \
|
||||
(((n)->type == XML_ELEMENT_NODE) || \
|
||||
((n)->type == XML_TEXT_NODE) || \
|
||||
((n)->type == XML_ATTRIBUTE_NODE) || \
|
||||
((n)->type == XML_DOCUMENT_NODE) || \
|
||||
((n)->type == XML_HTML_DOCUMENT_NODE) || \
|
||||
((n)->type == XML_DOCB_DOCUMENT_NODE)))
|
||||
#else
|
||||
#define IS_XSLT_REAL_NODE(n) \
|
||||
(((n) != NULL) && \
|
||||
(((n)->type == XML_ELEMENT_NODE) || \
|
||||
((n)->type == XML_TEXT_NODE) || \
|
||||
((n)->type == XML_ATTRIBUTE_NODE) || \
|
||||
((n)->type == XML_DOCUMENT_NODE) || \
|
||||
((n)->type == XML_HTML_DOCUMENT_NODE)))
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Our own version of namespaced atributes lookup
|
||||
*/
|
||||
|
||||
@@ -56,6 +56,7 @@ EXTRA_DIST = \
|
||||
bug-50-.xml \
|
||||
bug-52-.xml \
|
||||
bug-53-.xml \
|
||||
bug-54-.xml \
|
||||
character.xml \
|
||||
array.xml \
|
||||
items.xml
|
||||
|
||||
5
tests/docs/bug-54.xml
Normal file
5
tests/docs/bug-54.xml
Normal file
@@ -0,0 +1,5 @@
|
||||
<?xml version="1.0"?>
|
||||
<all>
|
||||
<one xmlns="http://www.test1.com">1</one>
|
||||
<two xmlns="http://www.test2.com">2</two>
|
||||
</all>
|
||||
@@ -58,6 +58,7 @@ EXTRA_DIST = \
|
||||
bug-50-.out bug-50-.xsl \
|
||||
bug-52-.out bug-52-.xsl \
|
||||
bug-53-.out bug-53-.xsl \
|
||||
bug-54-.out bug-54-.xsl \
|
||||
character.out character.xsl \
|
||||
character2.out character2.xsl \
|
||||
itemschoose.out itemschoose.xsl \
|
||||
|
||||
5
tests/general/bug-54.out
Normal file
5
tests/general/bug-54.out
Normal file
@@ -0,0 +1,5 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<root xmlns:libxslt="http://xmlsoft.org/XSLT/namespace" xmlns:test1="http://www.test1.com" xmlns:test2="http://www.test2.com" xmlns="http://www.test1.com">
|
||||
|
||||
|
||||
</root>
|
||||
22
tests/general/bug-54.xsl
Normal file
22
tests/general/bug-54.xsl
Normal file
@@ -0,0 +1,22 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<xsl:stylesheet
|
||||
version="1.0"
|
||||
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
|
||||
xmlns:libxslt="http://xmlsoft.org/XSLT/namespace"
|
||||
xmlns:test1="http://www.test1.com"
|
||||
xmlns:test2="http://www.test2.com"
|
||||
>
|
||||
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
|
||||
|
||||
<xsl:template match="/all/*">
|
||||
<xsl:for-each select="namespace::*">
|
||||
<xsl:copy-of select="."/>
|
||||
</xsl:for-each>
|
||||
</xsl:template>
|
||||
<xsl:template match="/">
|
||||
<root>
|
||||
<xsl:apply-templates/>
|
||||
</root>
|
||||
</xsl:template>
|
||||
|
||||
</xsl:stylesheet>
|
||||
Reference in New Issue
Block a user