Reviewed by Maciej.
authorap <ap@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 7 Jul 2007 10:00:38 +0000 (10:00 +0000)
committerap <ap@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 7 Jul 2007 10:00:38 +0000 (10:00 +0000)
        http://bugs.webkit.org/show_bug.cgi?id=14525
        Support exslt:node-set()

        Test: fast/xsl/exslt-node-set.xml

        * xml/XSLTExtensions.cpp: Added.
        (WebCore::exsltNodeSetFunction): A copy of exslt:node-set() implementation
        from libexslt 1.1.11 (shipped with Tiger).
        (WebCore::registerXSLTExtensions): This function registers any WebCore-provided
        extensions on a context. Currently, the only extension is exslt:node-set().
        * xml/XSLTExtensions.h: Added.

        * xml/XSLTProcessor.cpp:
        (WebCore::XSLTProcessor::transformToString):
        Register extensions when creating a context.

        * WebCore.pro:
        * WebCore.vcproj/WebCore.vcproj:
        * WebCore.xcodeproj/project.pbxproj:
        * WebCoreSources.bkl:
        Add XSLTExtensions.{h,cpp} to projects.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@24088 268f45cc-cd09-0410-ab3c-d52691b4dbfc

12 files changed:
LayoutTests/ChangeLog
LayoutTests/fast/xsl/exslt-node-set-expected.txt [new file with mode: 0644]
LayoutTests/fast/xsl/exslt-node-set.xml [new file with mode: 0644]
LayoutTests/fast/xsl/exslt-node-set.xsl [new file with mode: 0644]
WebCore/ChangeLog
WebCore/WebCore.pro
WebCore/WebCore.vcproj/WebCore.vcproj
WebCore/WebCore.xcodeproj/project.pbxproj
WebCore/WebCoreSources.bkl
WebCore/xml/XSLTExtensions.cpp [new file with mode: 0644]
WebCore/xml/XSLTExtensions.h [new file with mode: 0644]
WebCore/xml/XSLTProcessor.cpp

index 83d75e52480c4cbc3824afdd0c0d0856de0786d6..fd65503f1b2f0421be87045638a062380ddd6caf 100644 (file)
@@ -1,3 +1,14 @@
+2007-07-07  Alexey Proskuryakov  <ap@webkit.org>
+
+        Reviewed by Maciej.
+
+        http://bugs.webkit.org/show_bug.cgi?id=14525
+        Support exslt:node-set()
+
+        * fast/xsl/exslt-node-set-expected.txt: Added.
+        * fast/xsl/exslt-node-set.xml: Added.
+        * fast/xsl/exslt-node-set.xsl: Added.
+
 2007-07-06  Maciej Stachowiak  <mjs@apple.com>
 
         Reviewed by Oliver.
diff --git a/LayoutTests/fast/xsl/exslt-node-set-expected.txt b/LayoutTests/fast/xsl/exslt-node-set-expected.txt
new file mode 100644 (file)
index 0000000..ebf11a6
--- /dev/null
@@ -0,0 +1,3 @@
+Test that exslt:node-set() function is supported.
+
+SUCCESS
diff --git a/LayoutTests/fast/xsl/exslt-node-set.xml b/LayoutTests/fast/xsl/exslt-node-set.xml
new file mode 100644 (file)
index 0000000..8161646
--- /dev/null
@@ -0,0 +1,2 @@
+<?xml-stylesheet type="text/xsl" href="exslt-node-set.xsl"?>
+<doc/>
diff --git a/LayoutTests/fast/xsl/exslt-node-set.xsl b/LayoutTests/fast/xsl/exslt-node-set.xsl
new file mode 100644 (file)
index 0000000..1277ac8
--- /dev/null
@@ -0,0 +1,24 @@
+<xsl:stylesheet version="1.0" 
+               xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
+               xmlns:exslt="http://exslt.org/common"
+               exclude-result-prefixes="exslt">
+  
+<xsl:variable name="x">
+  <y/>
+</xsl:variable>
+
+<xsl:template match="doc">
+  <html>
+    <body>
+      <script>if (window.layoutTestController) layoutTestController.dumpAsText();</script>
+      <p>Test that exslt:node-set() function is supported.</p>
+      <xsl:apply-templates select="exslt:node-set($x)/*"/>
+    </body>
+  </html>
+</xsl:template>
+
+<xsl:template match="y">
+  <p>SUCCESS</p>
+</xsl:template>
+
+</xsl:stylesheet>
index a6de1e0bc6a9f2db194ba7bdf4c2fc68309c3cd2..91bdcd901ab0b6a76fd3eb461f572ce7beb59fe7 100644 (file)
@@ -1,3 +1,29 @@
+2007-07-07  Alexey Proskuryakov  <ap@webkit.org>
+
+        Reviewed by Maciej.
+
+        http://bugs.webkit.org/show_bug.cgi?id=14525
+        Support exslt:node-set()
+
+        Test: fast/xsl/exslt-node-set.xml
+
+        * xml/XSLTExtensions.cpp: Added.
+        (WebCore::exsltNodeSetFunction): A copy of exslt:node-set() implementation
+        from libexslt 1.1.11 (shipped with Tiger).
+        (WebCore::registerXSLTExtensions): This function registers any WebCore-provided
+        extensions on a context. Currently, the only extension is exslt:node-set().
+        * xml/XSLTExtensions.h: Added.
+
+        * xml/XSLTProcessor.cpp:
+        (WebCore::XSLTProcessor::transformToString):
+        Register extensions when creating a context.
+
+        * WebCore.pro:
+        * WebCore.vcproj/WebCore.vcproj:
+        * WebCore.xcodeproj/project.pbxproj:
+        * WebCoreSources.bkl:
+        Add XSLTExtensions.{h,cpp} to projects.
+
 2007-07-06  Maciej Stachowiak  <mjs@apple.com>
 
         Reviewed by Oliver.
index 6c82228e105dfb85fb655a617131d165483e3efd..e5b602f426ea9a940984e987a21577de1f382528 100644 (file)
@@ -716,6 +716,7 @@ SOURCES += \
     xml/XPathVariableReference.cpp \
     xml/XSLImportRule.cpp \
     xml/XSLStyleSheet.cpp \
+    xml/XSLTExtensions.cpp \
     xml/XSLTProcessor.cpp
 
 gdk-port {
index 8d5d323499ef91c4d68084783bbf138cd833bb80..0c57378dae916a29b529debea1d8543e10615702 100644 (file)
                                RelativePath="..\xml\XSLStyleSheet.h"
                                >
                        </File>
+                       <File
+                               RelativePath="..\xml\XSLTExtensions.cpp"
+                               >
+                       </File>
+                       <File
+                               RelativePath="..\xml\XSLTExtensions.h"
+                               >
+                       </File>
                        <File
                                RelativePath="..\xml\XSLTProcessor.cpp"
                                >
index 8c82a7539eeaa643ebb19ba0e9fa31d822500bf8..81be01fd14597992d452862f5f3838cd274cb989 100644 (file)
                E1EC29A00BB04C6B00EA187B /* XPathNodeSet.h in Headers */ = {isa = PBXBuildFile; fileRef = E1EC299E0BB04C6B00EA187B /* XPathNodeSet.h */; };
                E1F0424609839389006694EA /* xmlhttprequest.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E1F0424409839389006694EA /* xmlhttprequest.cpp */; };
                E1F0424709839389006694EA /* xmlhttprequest.h in Headers */ = {isa = PBXBuildFile; fileRef = E1F0424509839389006694EA /* xmlhttprequest.h */; };
+               E1F1E82F0C3C2BB9006DB391 /* XSLTExtensions.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E1F1E82D0C3C2BB9006DB391 /* XSLTExtensions.cpp */; };
+               E1F1E8300C3C2BB9006DB391 /* XSLTExtensions.h in Headers */ = {isa = PBXBuildFile; fileRef = E1F1E82E0C3C2BB9006DB391 /* XSLTExtensions.h */; };
                ED048ABC0833F132006E1E67 /* textAreaResizeCorner.tiff in Resources */ = {isa = PBXBuildFile; fileRef = ED048ABB0833F132006E1E67 /* textAreaResizeCorner.tiff */; };
                ED2BA83C09A24B91006C0AC4 /* DocumentMarker.h in Headers */ = {isa = PBXBuildFile; fileRef = ED2BA83B09A24B91006C0AC4 /* DocumentMarker.h */; settings = {ATTRIBUTES = (Private, ); }; };
                ED501DC60B249F2900AE18D9 /* EditorMac.mm in Sources */ = {isa = PBXBuildFile; fileRef = ED501DC50B249F2900AE18D9 /* EditorMac.mm */; };
                E1EC299E0BB04C6B00EA187B /* XPathNodeSet.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = XPathNodeSet.h; sourceTree = "<group>"; };
                E1F0424409839389006694EA /* xmlhttprequest.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = xmlhttprequest.cpp; sourceTree = "<group>"; };
                E1F0424509839389006694EA /* xmlhttprequest.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = xmlhttprequest.h; sourceTree = "<group>"; };
+               E1F1E82D0C3C2BB9006DB391 /* XSLTExtensions.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = XSLTExtensions.cpp; sourceTree = "<group>"; };
+               E1F1E82E0C3C2BB9006DB391 /* XSLTExtensions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = XSLTExtensions.h; sourceTree = "<group>"; };
                ED048ABB0833F132006E1E67 /* textAreaResizeCorner.tiff */ = {isa = PBXFileReference; lastKnownFileType = image.tiff; path = textAreaResizeCorner.tiff; sourceTree = "<group>"; };
                ED2BA83B09A24B91006C0AC4 /* DocumentMarker.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DocumentMarker.h; sourceTree = "<group>"; };
                ED501DC50B249F2900AE18D9 /* EditorMac.mm */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.objcpp; name = EditorMac.mm; path = mac/EditorMac.mm; sourceTree = "<group>"; };
                                85217E010A5ECD4700DB8D00 /* XSLImportRule.h */,
                                BC06F24906D18A7E004A6FA3 /* XSLStyleSheet.cpp */,
                                BC06F24A06D18A7E004A6FA3 /* XSLStyleSheet.h */,
+                               E1F1E82D0C3C2BB9006DB391 /* XSLTExtensions.cpp */,
+                               E1F1E82E0C3C2BB9006DB391 /* XSLTExtensions.h */,
                                BC06F24B06D18A7E004A6FA3 /* XSLTProcessor.cpp */,
                                BC06F24C06D18A7E004A6FA3 /* XSLTProcessor.h */,
                        );
                                BC5A86B60C3367E800EEA649 /* JSDOMSelection.h in Headers */,
                                BC073BAA0C399B1F000F5979 /* FloatConversion.h in Headers */,
                                BCA85A100C3AEAF4006F8308 /* DOMSVGNumberInternal.h in Headers */,
+                               E1F1E8300C3C2BB9006DB391 /* XSLTExtensions.h in Headers */,
                        );
                        runOnlyForDeploymentPostprocessing = 0;
                };
                                BCEFAF4E0C317E6900FA81F6 /* JSEventCustom.cpp in Sources */,
                                BC5A86840C33676000EEA649 /* DOMSelection.cpp in Sources */,
                                BC5A86B50C3367E800EEA649 /* JSDOMSelection.cpp in Sources */,
+                               E1F1E82F0C3C2BB9006DB391 /* XSLTExtensions.cpp in Sources */,
                        );
                        runOnlyForDeploymentPostprocessing = 0;
                };
index 6856a8a12d0577071f6b83cb18116119d4fa3c30..a48eada0b56f84d36e0c20d0b631f8064b1e33a8 100644 (file)
         xml/XPathVariableReference.cpp
         xml/XSLImportRule.cpp
         xml/XSLStyleSheet.cpp
+        xml/XSLTExtensions.cpp
         xml/XSLTProcessor.cpp
         xml/xmlhttprequest.cpp
     </set>
diff --git a/WebCore/xml/XSLTExtensions.cpp b/WebCore/xml/XSLTExtensions.cpp
new file mode 100644 (file)
index 0000000..05e60b2
--- /dev/null
@@ -0,0 +1,79 @@
+/**
+ * Copyright (C) 2001-2002 Thomas Broyer, Charlie Bozeman and Daniel Veillard.
+ * Copyright (C) 2007 Alexey Proskuryakov <ap@webkit.org>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is fur-
+ * nished to do so, subject to the following conditions:
+ * 
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ * 
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FIT-
+ * NESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+ * AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
+ * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CON-
+ * NECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ * 
+ * Except as contained in this notice, the name of the authors shall not
+ * be used in advertising or otherwise to promote the sale, use or other deal-
+ * ings in this Software without prior written authorization from him.
+ */
+
+#include "config.h"
+
+#if ENABLE(XSLT)
+
+#include <libxml/xpathInternals.h>
+
+#include <libxslt/xsltutils.h>
+#include <libxslt/extensions.h>
+#include <libxslt/extra.h>
+
+namespace WebCore {
+
+// FIXME: This code is taken from libexslt 1.1.11; should sync with newer versions.
+static void exsltNodeSetFunction(xmlXPathParserContextPtr ctxt, int nargs)
+{
+    xmlChar *strval;
+    xmlNodePtr retNode;
+    xmlXPathObjectPtr ret;
+
+    if (nargs != 1) {
+        xmlXPathSetArityError(ctxt);
+        return;
+    }
+
+    if (xmlXPathStackIsNodeSet(ctxt)) {
+        xsltFunctionNodeSet(ctxt, nargs);
+        return;
+    }
+
+    strval = xmlXPathPopString(ctxt);
+    retNode = xmlNewDocText(NULL, strval);
+    ret = xmlXPathNewValueTree(retNode);
+    if (ret == NULL) {
+        xsltGenericError(xsltGenericErrorContext,
+                         "exsltNodeSetFunction: ret == NULL\n");
+    } else {
+        ret->type = XPATH_NODESET;
+    }
+
+    if (strval != NULL)
+        xmlFree(strval);
+
+    valuePush(ctxt, ret);
+}
+
+void registerXSLTExtensions(xsltTransformContextPtr ctxt)
+{
+    xsltRegisterExtFunction(ctxt, (const xmlChar*)"node-set", (const xmlChar*)"http://exslt.org/common", exsltNodeSetFunction);
+}
+
+}
+
+#endif
diff --git a/WebCore/xml/XSLTExtensions.h b/WebCore/xml/XSLTExtensions.h
new file mode 100644 (file)
index 0000000..4e4224f
--- /dev/null
@@ -0,0 +1,40 @@
+/**
+ * Copyright (C) 2007 Alexey Proskuryakov <ap@webkit.org>
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef XSLTExtensions_h
+#define XSLTExtensions_h
+
+#if ENABLE(XSLT)
+
+#include <libxslt/xsltInternals.h>
+
+namespace WebCore {
+
+void registerXSLTExtensions(xsltTransformContextPtr ctxt);
+
+}
+
+#endif
+#endif
index 54624450f0fbfb60044edacc2815e0fb261c7df3..d7f27cc2300927a1c5a00aefe8a2840fa89f62e4 100644 (file)
@@ -42,6 +42,7 @@
 #include "Text.h"
 #include "TextResourceDecoder.h"
 #include "XMLTokenizer.h"
+#include "XSLTExtensions.h"
 #include "loader.h"
 #include "markup.h"
 #include <libxslt/imports.h>
@@ -324,6 +325,7 @@ bool XSLTProcessor::transformToString(Node *sourceNode, DeprecatedString &mimeTy
         sheet->omitXmlDeclaration = true;
 
         xsltTransformContextPtr transformContext = xsltNewTransformContext(sheet, sourceDoc);
+        registerXSLTExtensions(transformContext);
 
         // This is a workaround for a bug in libxslt. 
         // The bug has been fixed in version 1.1.13, so once we ship that this can be removed.