Forwards-compatible processing of unknown top level elements
authorNick Wellnhofer <wellnhofer@aevum.de>
Wed, 15 Aug 2012 20:40:05 +0000 (22:40 +0200)
committerDaniel Veillard <veillard@redhat.com>
Thu, 16 Aug 2012 08:21:13 +0000 (16:21 +0800)
Bug #677901

libxslt/xslt.c
libxslt/xsltInternals.h
tests/docs/bug-175.xml [new file with mode: 0644]
tests/general/bug-175.err [new file with mode: 0644]
tests/general/bug-175.out [new file with mode: 0644]
tests/general/bug-175.xsl [new file with mode: 0644]

index 2bc8af5..bd14092 100644 (file)
@@ -758,6 +758,7 @@ xsltNewStylesheet(void) {
     ret->extrasNr = 0;
     ret->internalized = 1;
     ret->literal_result = 0;
+    ret->forwards_compatible = 0;
     ret->dict = xmlDictCreate();
 #ifdef WITH_XSLT_DEBUG
     xsltGenericDebug(xsltGenericDebugContext,
@@ -6068,8 +6069,10 @@ xsltParseStylesheetTop(xsltStylesheetPtr style, xmlNodePtr top) {
             (!xmlStrEqual(prop, (const xmlChar *)"1.1"))) {
            xsltTransformError(NULL, style, top,
                "xsl:version: only 1.0 features are supported\n");
-            /* TODO set up compatibility when not XSLT 1.0 */
-           if (style != NULL) style->warnings++;
+           if (style != NULL) {
+                style->forwards_compatible = 1;
+                style->warnings++;
+            }
        }
        xmlFree(prop);
     }
@@ -6163,12 +6166,7 @@ xsltParseStylesheetTop(xsltStylesheetPtr style, xmlNodePtr top) {
     } else if (IS_XSLT_NAME(cur, "namespace-alias")) {
            xsltNamespaceAlias(style, cur);
        } else {
-           /*
-           * BUG TODO: The version of the *doc* is irrelevant for
-           *  the forwards-compatible mode.
-           */
-            if ((style != NULL) && (style->doc->version != NULL) &&
-               (!strncmp((const char *) style->doc->version, "1.0", 3))) {
+            if ((style != NULL) && (style->forwards_compatible == 0)) {
                xsltTransformError(NULL, style, cur,
                        "xsltParseStylesheetTop: unknown %s element\n",
                        cur->name);
index afb2a2c..5be59bc 100644 (file)
@@ -1635,6 +1635,10 @@ struct _xsltStylesheet {
 
     xsltPrincipalStylesheetDataPtr principalData;    
 #endif
+    /*
+     * Forwards-compatible processing
+     */
+    int forwards_compatible;
 };
 
 typedef struct _xsltTransformCache xsltTransformCache;
diff --git a/tests/docs/bug-175.xml b/tests/docs/bug-175.xml
new file mode 100644 (file)
index 0000000..69d62f2
--- /dev/null
@@ -0,0 +1 @@
+<doc/>
diff --git a/tests/general/bug-175.err b/tests/general/bug-175.err
new file mode 100644 (file)
index 0000000..70cddd5
--- /dev/null
@@ -0,0 +1,6 @@
+compilation error: file ./bug-175.xsl line 28 element function
+xsltStylePreCompute: unknown xsl:function
+compilation error: file ./bug-175.xsl line 5 element transform
+xsl:version: only 1.0 features are supported
+compilation error: file ./bug-175.xsl line 28 element function
+xsltParseStylesheetTop: ignoring unknown function element
diff --git a/tests/general/bug-175.out b/tests/general/bug-175.out
new file mode 100644 (file)
index 0000000..e9cf403
--- /dev/null
@@ -0,0 +1,8 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN">
+<html>
+<head>
+<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
+<title>xsl:function</title>
+</head>
+<body><p><tt>xsl:function</tt> not supported, but properly handled (ignored)</p></body>
+</html>
diff --git a/tests/general/bug-175.xsl b/tests/general/bug-175.xsl
new file mode 100644 (file)
index 0000000..f25e4c9
--- /dev/null
@@ -0,0 +1,30 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
+               xmlns:test="#test"
+               exclude-result-prefixes="test"
+               version="2.0">
+   <xsl:output method="html" encoding="iso-8859-1" version="4.0"
+               doctype-public="-//W3C//DTD HTML 4.01//EN"
+               indent="yes"/>
+
+   <xsl:template match="/">
+      <html>
+         <head>
+            <title>xsl:function</title>
+         </head>
+         <body>
+            <xsl:choose>
+               <xsl:when test="function-available('test:test')">
+                  <p>Result: <xsl:value-of select="test:test()"/></p>
+               </xsl:when>
+               <xsl:otherwise>
+                  <p><tt>xsl:function</tt> not supported, but properly handled (ignored)</p>
+               </xsl:otherwise>
+            </xsl:choose>
+         </body>
+      </html>
+   </xsl:template>
+
+   <xsl:function name="test:test">YES</xsl:function>
+
+</xsl:transform>