Cleanup: - transform.c: fixed text and cdata handling in xsl:copy - xslt.c
authorDaniel Veillard <veillard@src.gnome.org>
Wed, 25 Apr 2001 15:05:54 +0000 (15:05 +0000)
committerDaniel Veillard <veillard@src.gnome.org>
Wed, 25 Apr 2001 15:05:54 +0000 (15:05 +0000)
Cleanup:
- transform.c: fixed text and cdata handling in xsl:copy
- xslt.c : avoid crashing on invalid xslt input
- test/general/bug-*.* test/docs/bug-*.xml : added a number of
  bugs submitted to the regression tests
Daniel

26 files changed:
ChangeLog
libxslt/transform.c
libxslt/xslt.c
tests/docs/bug-10-.xml [new file with mode: 0644]
tests/docs/bug-11-.xml [new file with mode: 0644]
tests/docs/bug-12-.xml [new file with mode: 0644]
tests/docs/bug-13-.xml [new file with mode: 0644]
tests/docs/bug-4-.xml [new file with mode: 0644]
tests/docs/bug-7-.xml [new file with mode: 0644]
tests/docs/bug-8-.xml [new file with mode: 0644]
tests/general/bug-10-.out [new file with mode: 0644]
tests/general/bug-10-.xsl [new file with mode: 0644]
tests/general/bug-11-.out [new file with mode: 0644]
tests/general/bug-11-.xsl [new file with mode: 0644]
tests/general/bug-12-.out [new file with mode: 0644]
tests/general/bug-12-.xsl [new file with mode: 0644]
tests/general/bug-13-.out [new file with mode: 0644]
tests/general/bug-13-.xsl [new file with mode: 0644]
tests/general/bug-4-.out [new file with mode: 0644]
tests/general/bug-4-.xsl [new file with mode: 0644]
tests/general/bug-7-.out [new file with mode: 0644]
tests/general/bug-7-.xsl [new file with mode: 0644]
tests/general/bug-8-.out [new file with mode: 0644]
tests/general/bug-8-.xsl [new file with mode: 0644]
tests/general/bug-9-.out [new file with mode: 0644]
tests/xmlspec/Makefile.am

index 05e8e7d162206daff9cc42f52c77d1ffb6773343..e2bd94eb9bbb0f0a850e127010aceb43b977704d 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+Wed Apr 25 16:58:11 CEST 2001 Daniel Veillard <Daniel.Veillard@imag.fr>
+
+       * transform.c: fixed text and cdata handling in xsl:copy
+       * xslt.c : avoid crashing on invalid xslt input
+       * test/general/bug-*.* test/docs/bug-*.xml : added a number of
+         bugs submitted to the regression tests
+
 Wed Apr 25 12:42:48 CEST 2001 Daniel Veillard <Daniel.Veillard@imag.fr>
 
        * libxslt/xsltproc.c : Renaud Chaillat provided a fix for #53535
index 449d0d2384429ff268ba3c373cb985d8e55aa787..9f751ed686d52a510622876147f0481adb471fe9 100644 (file)
@@ -1294,6 +1294,31 @@ xsltCopy(xsltTransformContextPtr ctxt, xmlNodePtr node,
     oldInsert = ctxt->insert;
     if (ctxt->insert != NULL) {
        switch (node->type) {
+           case XML_TEXT_NODE:
+           case XML_CDATA_SECTION_NODE:
+               /*
+                * This text comes from the stylesheet
+                * For stylesheets, the set of whitespace-preserving
+                * element names consists of just xsl:text.
+                */
+#ifdef WITH_XSLT_DEBUG_PROCESS
+               if (node->type == XML_CDATA_SECTION_NODE)
+                   xsltGenericDebug(xsltGenericDebugContext,
+                        "xsl:copy: CDATA text %s\n", node->content);
+               else
+                   xsltGenericDebug(xsltGenericDebugContext,
+                        "xsl:copy: text %s\n", node->content);
+#endif
+               copy = xmlNewText(node->content);
+               if (copy != NULL) {
+                   if (node->name == xmlStringTextNoenc)
+                       copy->name = xmlStringTextNoenc;
+                   xmlAddChild(ctxt->insert, copy);
+               } else {
+                   xsltGenericError(xsltGenericErrorContext,
+                           "xsl:copy: text copy failed\n");
+               }
+               break;
            case XML_DOCUMENT_NODE:
            case XML_HTML_DOCUMENT_NODE:
                break;
index 1ba710650fb491cfcf78bcc141b245d9aa983987..00114c0a9d6441eab7e356b263f185d0db903c0a 100644 (file)
@@ -781,7 +781,7 @@ xsltParseRemoveBlanks(xsltStylesheetPtr style) {
            xmlFreeNode(delete);
            delete = NULL;
        }
-       if (IS_XSLT_ELEM(cur)) {
+       if ((cur->type == XML_ELEMENT_NODE) && (IS_XSLT_ELEM(cur))) {
            if (IS_XSLT_NAME(cur, "text")) {
                goto skip_children;
            }
@@ -793,13 +793,16 @@ xsltParseRemoveBlanks(xsltStylesheetPtr style) {
            }
        } else if (cur->type != XML_ELEMENT_NODE) {
            delete = cur;
+           goto skip_children;
        }
 
        /*
         * Skip to next node
         */
        if (cur->children != NULL) {
-           if (cur->children->type != XML_ENTITY_DECL) {
+           if ((cur->children->type != XML_ENTITY_DECL) &&
+               (cur->children->type != XML_ENTITY_REF_NODE) &&
+               (cur->children->type != XML_ENTITY_NODE)) {
                cur = cur->children;
                continue;
            }
@@ -1423,6 +1426,7 @@ xsltParseStylesheetProcess(xsltStylesheetPtr ret, xmlDocPtr doc) {
     if (cur == NULL) {
         xsltGenericError(xsltGenericErrorContext,
                "xsltParseStylesheetProcess : empty stylesheet\n");
+       ret->doc = NULL;
        xsltFreeStylesheet(ret);
        return(NULL);
     }
@@ -1448,6 +1452,7 @@ xsltParseStylesheetProcess(xsltStylesheetPtr ret, xmlDocPtr doc) {
        if (prop == NULL) {
            xsltGenericError(xsltGenericErrorContext,
                "xsltParseStylesheetProcess : document is not a stylesheet\n");
+           ret->doc = NULL;
            xsltFreeStylesheet(ret);
            return(NULL);
        }
@@ -1469,6 +1474,7 @@ xsltParseStylesheetProcess(xsltStylesheetPtr ret, xmlDocPtr doc) {
         */
        template = xsltNewTemplate();
        if (template == NULL) {
+           ret->doc = NULL;
            xsltFreeStylesheet(ret);
            return(NULL);
        }
@@ -1508,7 +1514,7 @@ xsltParseStylesheetDoc(xmlDocPtr doc) {
     
     ret->doc = doc;
     xsltGatherNamespaces(ret);
-    xsltParseStylesheetProcess(ret, doc);
+    ret = xsltParseStylesheetProcess(ret, doc);
 
     return(ret);
 }
diff --git a/tests/docs/bug-10-.xml b/tests/docs/bug-10-.xml
new file mode 100644 (file)
index 0000000..f381066
--- /dev/null
@@ -0,0 +1,3 @@
+<?xml version= "1.0"?>
+<doc/>
+
diff --git a/tests/docs/bug-11-.xml b/tests/docs/bug-11-.xml
new file mode 100644 (file)
index 0000000..64fe27f
--- /dev/null
@@ -0,0 +1,4 @@
+<?xml version= "1.0"?>
+
+<doc/>
+
diff --git a/tests/docs/bug-12-.xml b/tests/docs/bug-12-.xml
new file mode 100644 (file)
index 0000000..af18b36
--- /dev/null
@@ -0,0 +1,9 @@
+<?xml version='1.0' encoding="ISO-8859-1"?>
+
+<test:schema xmlns:test="http://test.com"
+             xmlns:xlink="http://xlink.com">
+<test:root >
+   <test:child>
+   </test:child>
+</test:root>
+</test:schema>
diff --git a/tests/docs/bug-13-.xml b/tests/docs/bug-13-.xml
new file mode 100644 (file)
index 0000000..a01ae29
--- /dev/null
@@ -0,0 +1 @@
+<some>text</some>
diff --git a/tests/docs/bug-4-.xml b/tests/docs/bug-4-.xml
new file mode 100644 (file)
index 0000000..db0534d
--- /dev/null
@@ -0,0 +1,38 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ROOT>
+  <GROUP name="G1">
+    <MEMBER name="M1">
+      <CONTENT>MEMBER 1 of GROUP 1</CONTENT>
+    </MEMBER>
+    <MEMBER name="M2">
+      <CONTENT>MEMBER 2 of GROUP 1</CONTENT>
+    </MEMBER>
+    <MEMBER name="M3">
+      <CONTENT>MEMBER 3 of GROUP 1</CONTENT>
+    </MEMBER>
+  </GROUP>
+
+  <GROUP name="G2">
+    <MEMBER name="M1">
+      <CONTENT>MEMBER 1 of GROUP 2</CONTENT>
+    </MEMBER>
+    <MEMBER name="M2">
+      <CONTENT>MEMBER 2 of GROUP 2</CONTENT>
+    </MEMBER>
+    <MEMBER name="M3">
+      <CONTENT>MEMBER 3 of GROUP 2</CONTENT>
+    </MEMBER>
+  </GROUP>
+
+  <GROUP name="G3">
+    <MEMBER name="M1">
+      <CONTENT>MEMBER 1 of GROUP 3</CONTENT>
+    </MEMBER>
+    <MEMBER name="M2">
+      <CONTENT>MEMBER 2 of GROUP 3</CONTENT>
+    </MEMBER>
+    <MEMBER name="M3">
+      <CONTENT>MEMBER 3 of GROUP 3</CONTENT>
+    </MEMBER>
+  </GROUP>
+</ROOT>
diff --git a/tests/docs/bug-7-.xml b/tests/docs/bug-7-.xml
new file mode 100644 (file)
index 0000000..171d61b
--- /dev/null
@@ -0,0 +1,3 @@
+<?xml version="1.0"?>
+
+<aaa xmlns:bbb="test:7" bbb:ddd="ccc" eee="fff"/>
diff --git a/tests/docs/bug-8-.xml b/tests/docs/bug-8-.xml
new file mode 100644 (file)
index 0000000..975f42d
--- /dev/null
@@ -0,0 +1,5 @@
+<?xml version= "1.0"?>
+<document xmlns="http://my/namespace">
+  <item>Success</item>
+</document>
+
diff --git a/tests/general/bug-10-.out b/tests/general/bug-10-.out
new file mode 100644 (file)
index 0000000..77c975e
--- /dev/null
@@ -0,0 +1,2 @@
+<?xml version="1.0"?>
+Success
diff --git a/tests/general/bug-10-.xsl b/tests/general/bug-10-.xsl
new file mode 100644 (file)
index 0000000..300580f
--- /dev/null
@@ -0,0 +1,10 @@
+<?xml version= "1.0"?>
+                            
+<xsl:stylesheet version="1.0" 
+  xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
+  
+<xsl:template match="/">
+<xsl:text><![CDATA[Success]]></xsl:text>
+</xsl:template>
+  
+</xsl:stylesheet>
diff --git a/tests/general/bug-11-.out b/tests/general/bug-11-.out
new file mode 100644 (file)
index 0000000..e4236f9
--- /dev/null
@@ -0,0 +1,2 @@
+<!DOCTYPE HTML PUBLIC "http://www.w3.org/TR/REC-html40/loose.dtd" "-//W3C//DTD HTML 4.0 Transitional//EN">
+<?php Success>
diff --git a/tests/general/bug-11-.xsl b/tests/general/bug-11-.xsl
new file mode 100644 (file)
index 0000000..0aefcbe
--- /dev/null
@@ -0,0 +1,12 @@
+<?xml version= "1.0"?>
+                             
+<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
+
+<xsl:output method="html"/>
+<!--xsl:import href="test2.xsl"/-->
+
+<xsl:template match="/">
+<xsl:processing-instruction name="php">Success</xsl:processing-instruction>
+</xsl:template>
+   
+</xsl:stylesheet>
diff --git a/tests/general/bug-12-.out b/tests/general/bug-12-.out
new file mode 100644 (file)
index 0000000..b63ec6c
--- /dev/null
@@ -0,0 +1,2 @@
+<?xml version="1.0" encoding="ISO-8859-1"?>
+<namespace>http://test.com</namespace>
diff --git a/tests/general/bug-12-.xsl b/tests/general/bug-12-.xsl
new file mode 100644 (file)
index 0000000..e6d199f
--- /dev/null
@@ -0,0 +1,16 @@
+<?xml version='1.0' encoding="ISO-8859-1"?>
+
+<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
+
+<xsl:output method="xml"
+            version="1.0"
+           encoding="ISO-8859-1"
+           indent="yes" />
+           
+<xsl:template match="/">
+   <namespace>
+   <xsl:value-of select="//namespace::*"/>
+   </namespace>
+</xsl:template>
+
+</xsl:stylesheet>
diff --git a/tests/general/bug-13-.out b/tests/general/bug-13-.out
new file mode 100644 (file)
index 0000000..ddf7628
--- /dev/null
@@ -0,0 +1,2 @@
+<?xml version="1.0"?>
+<some>text</some>
diff --git a/tests/general/bug-13-.xsl b/tests/general/bug-13-.xsl
new file mode 100644 (file)
index 0000000..156cd07
--- /dev/null
@@ -0,0 +1,10 @@
+<xsl:stylesheet version="1.0"
+  xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
+
+<xsl:template match="*|@*|text()">
+  <xsl:copy>
+    <xsl:apply-templates select="*|@*|text()"/>
+  </xsl:copy>
+</xsl:template>
+
+</xsl:stylesheet>
diff --git a/tests/general/bug-4-.out b/tests/general/bug-4-.out
new file mode 100644 (file)
index 0000000..6a18c1b
--- /dev/null
@@ -0,0 +1,7 @@
+<?xml version="1.0"?>
+<MEMBER name="M2">
+      <CONTENT>MEMBER 2 of GROUP 2</CONTENT>
+    </MEMBER>
+<MEMBER name="M2">
+      <CONTENT>MEMBER 2 of GROUP 3</CONTENT>
+    </MEMBER>
diff --git a/tests/general/bug-4-.xsl b/tests/general/bug-4-.xsl
new file mode 100644 (file)
index 0000000..9843c3b
--- /dev/null
@@ -0,0 +1,12 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<xsl:stylesheet version="1.0"
+xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
+<xsl:template match="/">
+      <xsl:apply-templates select="ROOT"/>
+</xsl:template>
+<xsl:template match="ROOT">
+      <xsl:for-each select="GROUP[position() != 1]/MEMBER[2]">
+            <xsl:copy-of select="."/>
+      </xsl:for-each>
+</xsl:template>
+</xsl:stylesheet>
diff --git a/tests/general/bug-7-.out b/tests/general/bug-7-.out
new file mode 100644 (file)
index 0000000..53ae588
--- /dev/null
@@ -0,0 +1,2 @@
+<?xml version="1.0"?>
+cccfff
diff --git a/tests/general/bug-7-.xsl b/tests/general/bug-7-.xsl
new file mode 100644 (file)
index 0000000..755ebd3
--- /dev/null
@@ -0,0 +1,11 @@
+<?xml version="1.0"?>
+<xsl:stylesheet version="1.0"
+xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
+xmlns:bbb="test:7">
+
+  <xsl:template match="aaa">
+    <xsl:value-of select="@bbb:ddd"/>
+    <xsl:value-of select="@eee"/>
+  </xsl:template>
+
+</xsl:stylesheet>
diff --git a/tests/general/bug-8-.out b/tests/general/bug-8-.out
new file mode 100644 (file)
index 0000000..9f6689b
--- /dev/null
@@ -0,0 +1,3 @@
+<?xml version="1.0"?>
+
+    Big 
diff --git a/tests/general/bug-8-.xsl b/tests/general/bug-8-.xsl
new file mode 100644 (file)
index 0000000..40333e8
--- /dev/null
@@ -0,0 +1,13 @@
+<?xml version= "1.0"?>
+                            
+<xsl:stylesheet version="1.0" 
+  xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
+  
+  <xsl:import href="inner.xsl"/>
+  
+  <!-- Root Node -->
+  <xsl:template match="/">
+    <xsl:apply-templates/>
+  </xsl:template>
+  
+</xsl:stylesheet>
diff --git a/tests/general/bug-9-.out b/tests/general/bug-9-.out
new file mode 100644 (file)
index 0000000..70670fa
--- /dev/null
@@ -0,0 +1,2 @@
+<?xml version="1.0"?>
+<?php Success?>
index fcb120d17061e3d36675638456f7012eddd6d46b..545c3c9f007ce8583d14d895f2b8dbd4c3fba79a 100644 (file)
@@ -4,7 +4,8 @@ $(top_builddir)/libxslt/xsltproc:
        @(cd ../../libxslt ; make xsltproc)
 
 EXTRA_DIST = REC-xml-20001006.xml xmlspec-v21.dtd W3C-REC.css \
-             logo-REC xmlspec.xsl REC-xml-2e.xsl diffspec.xsl
+             logo-REC xmlspec.xsl REC-xml-2e.xsl diffspec.xsl \
+            REC-xml-20001006.html REC-xml-20001006-review.html
 
 all: test