Norm pointed out that element-available() didn't work, implemented it
authorDaniel Veillard <veillard@src.gnome.org>
Sun, 8 Jul 2001 20:21:05 +0000 (20:21 +0000)
committerDaniel Veillard <veillard@src.gnome.org>
Sun, 8 Jul 2001 20:21:05 +0000 (20:21 +0000)
* libxslt/extra.c libxslt/functions.c libxslt/transform.[ch]
  libxslt/variables.h: Norm pointed out that element-available()
  didn't work, implemented it
* tests/extensions/Makefile.am tests/extensions/list.*: added
  a test for all registered xslt element, function and default
  extensions.
Daniel

ChangeLog
libxslt/extra.c
libxslt/functions.c
libxslt/transform.c
libxslt/transform.h
libxslt/variables.h
tests/extensions/Makefile.am
tests/extensions/list.out [new file with mode: 0644]
tests/extensions/list.xml [new file with mode: 0644]
tests/extensions/list.xsl [new file with mode: 0644]

index 157caf7e5ce1adfb5736899158412396ad700fe8..ba22f5809161eb8ae1a92dd05db022f44023f5fd 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+Sun Jul  8 22:12:02 CEST 2001 Daniel Veillard <Daniel.Veillard@imag.fr>
+
+       * libxslt/extra.c libxslt/functions.c libxslt/transform.[ch]
+         libxslt/variables.h: Norm pointed out that element-available()
+         didn't work, implemented it
+       * tests/extensions/Makefile.am tests/extensions/list.*: added
+         a test for all registered xslt element, function and default
+         extensions.
+
 Sun Jul  8 20:44:25 CEST 2001 Daniel Veillard <Daniel.Veillard@imag.fr>
 
        * tests/documents/Makefile.am 'tests/documents/doc file.xml'
index 223e3d9fe081e8deddbbb9054c1eb9126b641fc5..17f8208704ca337eadfa1ddf3dc372b92fa68eb1 100644 (file)
@@ -179,7 +179,7 @@ xsltRegisterExtras(xsltTransformContextPtr ctxt) {
     xsltRegisterExtElement(ctxt, (const xmlChar *) "output",
                            XSLT_SAXON_NAMESPACE, xsltDocumentElem);
     xsltRegisterExtElement(ctxt, (const xmlChar *) "write",
-                           XSLT_SAXON_NAMESPACE, xsltDocumentElem);
+                           XSLT_XALAN_NAMESPACE, xsltDocumentElem);
     xsltRegisterExtElement(ctxt, (const xmlChar *) "document",
                            XSLT_XT_NAMESPACE, xsltDocumentElem);
 }
index 3c66905dc73f9b9cc91313b74a3b776ee731b46d..a4bc1c1ea44093ad57c77ea83ef609618cdb9248 100644 (file)
@@ -568,6 +568,9 @@ xsltSystemPropertyFunction(xmlXPathParserContextPtr ctxt, int nargs){
 void
 xsltElementAvailableFunction(xmlXPathParserContextPtr ctxt, int nargs){
     xmlXPathObjectPtr obj;
+    xmlChar *prefix, *name;
+    const xmlChar *nsURI = NULL;
+    xsltTransformContextPtr tctxt;
 
     if (nargs != 1) {
         xsltGenericError(xsltGenericErrorContext,
@@ -582,8 +585,38 @@ xsltElementAvailableFunction(xmlXPathParserContextPtr ctxt, int nargs){
        return;
     }
     obj = valuePop(ctxt);
+    tctxt = xsltXPathGetTransformContext(ctxt);
+    if (tctxt == NULL) {
+       xsltGenericError(xsltGenericErrorContext,
+               "element-available() : internal error tctxt == NULL\n");
+       xmlXPathFreeObject(obj);
+       valuePush(ctxt, xmlXPathNewBoolean(0));
+       return;
+    }
+
+
+    name = xmlSplitQName2(obj->stringval, &prefix);
+    if (name == NULL) {
+       name = xmlStrdup(obj->stringval);
+    } else {
+       nsURI = xmlXPathNsLookup(ctxt->context, prefix);
+       if (nsURI == NULL) {
+           xsltGenericError(xsltGenericErrorContext,
+               "element-available() : prefix %s is not bound\n", prefix);
+       }
+    }
+
+    if (xmlHashLookup2(tctxt->extElements, name, nsURI) != NULL) {
+       valuePush(ctxt, xmlXPathNewBoolean(1));
+    } else {
+       valuePush(ctxt, xmlXPathNewBoolean(0));
+    }
+
     xmlXPathFreeObject(obj);
-    valuePush(ctxt, xmlXPathNewBoolean(0));
+    if (name != NULL)
+       xmlFree(name);
+    if (prefix != NULL)
+       xmlFree(prefix);
 }
 
 /**
index 315145cab095add47d7ce175ccacde49f6ff0ef8..b1096f177a14c22f6824789d1e4239d686bc0b63 100644 (file)
@@ -3325,3 +3325,67 @@ xsltRunStylesheet(xsltStylesheetPtr style, xmlDocPtr doc,
     xmlFreeDoc(tmp);
     return (ret);
 }
+
+/**
+ * xsltRegisterAllElements:
+ * @ctxt:  the XPath context
+ *
+ * Registers all default XSLT elements in this context
+ */
+void
+xsltRegisterAllElement(xsltTransformContextPtr ctxt)
+{
+    xsltRegisterExtElement(ctxt, (const xmlChar *) "apply-templates",
+                           XSLT_NAMESPACE, xsltApplyTemplates);
+    xsltRegisterExtElement(ctxt, (const xmlChar *) "apply-imports",
+                           XSLT_NAMESPACE, xsltApplyImports);
+    xsltRegisterExtElement(ctxt, (const xmlChar *) "call-template",
+                           XSLT_NAMESPACE, xsltCallTemplate);
+    xsltRegisterExtElement(ctxt, (const xmlChar *) "element",
+                           XSLT_NAMESPACE, xsltElement);
+    xsltRegisterExtElement(ctxt, (const xmlChar *) "attribute",
+                           XSLT_NAMESPACE, xsltAttribute);
+    xsltRegisterExtElement(ctxt, (const xmlChar *) "text",
+                           XSLT_NAMESPACE, xsltText);
+    xsltRegisterExtElement(ctxt, (const xmlChar *) "processing-instruction",
+                           XSLT_NAMESPACE, xsltProcessingInstruction);
+    xsltRegisterExtElement(ctxt, (const xmlChar *) "comment",
+                           XSLT_NAMESPACE, xsltComment);
+    xsltRegisterExtElement(ctxt, (const xmlChar *) "copy",
+                           XSLT_NAMESPACE, xsltCopy);
+    xsltRegisterExtElement(ctxt, (const xmlChar *) "value-of",
+                           XSLT_NAMESPACE, xsltValueOf);
+    xsltRegisterExtElement(ctxt, (const xmlChar *) "number",
+                           XSLT_NAMESPACE, xsltNumber);
+    xsltRegisterExtElement(ctxt, (const xmlChar *) "for-each",
+                           XSLT_NAMESPACE, xsltForEach);
+    xsltRegisterExtElement(ctxt, (const xmlChar *) "if",
+                           XSLT_NAMESPACE, xsltIf);
+    xsltRegisterExtElement(ctxt, (const xmlChar *) "choose",
+                           XSLT_NAMESPACE, xsltChoose);
+    xsltRegisterExtElement(ctxt, (const xmlChar *) "sort",
+                           XSLT_NAMESPACE, xsltSort);
+    xsltRegisterExtElement(ctxt, (const xmlChar *) "copy-of",
+                           XSLT_NAMESPACE, xsltCopyOf);
+    xsltRegisterExtElement(ctxt, (const xmlChar *) "message",
+                           XSLT_NAMESPACE, xsltMessage);
+
+    /*
+     * Those don't have callable entry points but are registered anyway
+     */
+    xsltRegisterExtElement(ctxt, (const xmlChar *) "variable",
+                           XSLT_NAMESPACE, xsltDebug);
+    xsltRegisterExtElement(ctxt, (const xmlChar *) "param",
+                           XSLT_NAMESPACE, xsltDebug);
+    xsltRegisterExtElement(ctxt, (const xmlChar *) "with-param",
+                           XSLT_NAMESPACE, xsltDebug);
+    xsltRegisterExtElement(ctxt, (const xmlChar *) "decimal-format",
+                           XSLT_NAMESPACE, xsltDebug);
+    xsltRegisterExtElement(ctxt, (const xmlChar *) "when",
+                           XSLT_NAMESPACE, xsltDebug);
+    xsltRegisterExtElement(ctxt, (const xmlChar *) "otherwise",
+                           XSLT_NAMESPACE, xsltDebug);
+    xsltRegisterExtElement(ctxt, (const xmlChar *) "fallback",
+                           XSLT_NAMESPACE, xsltDebug);
+
+}
index 4406751abbd093acdc22b151f0d37cc06fd8e137..dd4b3e96ff3a3e16fc4c88b88c3f9db062d235d3 100644 (file)
@@ -112,7 +112,7 @@ void                xsltForEach             (xsltTransformContextPtr ctxt,
                                         xmlNodePtr node,
                                         xmlNodePtr inst,
                                         xsltStylePreCompPtr comp);
-
+void           xsltRegisterAllElement  (xsltTransformContextPtr ctxt);
 #ifdef __cplusplus
 }
 #endif
index 2cdafd0545e450dda6f0024085b9d4ee84ecb8ab..135b42801f8a33d4045568c0a4c0be192bdbb25b 100644 (file)
@@ -29,6 +29,7 @@ extern "C" {
     xmlXPathRegisterVariableLookup((ctxt)->xpathCtxt,          \
               xsltXPathVariableLookup, (void *)(ctxt));        \
     xsltRegisterAllFunctions((ctxt)->xpathCtxt);               \
+    xsltRegisterAllElement(ctxt);                              \
     (ctxt)->xpathCtxt->extra = ctxt
 
 /*
index 2bf71a9301e47e26380b862f999db2d93d4cfa53..8db24e26134067d8b7b147ce29e601ac38aa6840 100644 (file)
@@ -4,7 +4,8 @@ $(top_builddir)/libxslt/xsltproc:
        @(cd ../../libxslt ; make xsltproc)
 
 EXTRA_DIST = \
-    module.xml module.xsl module.out
+    module.xml module.xsl module.out \
+    list.xml list.xsl list.out
 
 
 all: test
diff --git a/tests/extensions/list.out b/tests/extensions/list.out
new file mode 100644 (file)
index 0000000..4484363
--- /dev/null
@@ -0,0 +1,37 @@
+<?xml version="1.0"?>
+ === 24 Standard elements:
+xsl:apply-templates available
+xsl:apply-imports available
+xsl:call-template available
+xsl:element available
+xsl:attribute available
+xsl:text available
+xsl:processing-instruction available
+xsl:comment available
+xsl:copy available
+xsl:value-of available
+xsl:number available
+xsl:for-each available
+xsl:if available
+xsl:choose available
+xsl:sort available
+xsl:copy-of available
+xsl:message available
+xsl:variable available
+xsl:param available
+xsl:with-param available
+xsl:decimal-format available
+xsl:when available
+xsl:otherwise available
+xsl:fallback available
+ === 5 Extension elements:
+xsl:element available
+saxon:output available
+xalanredirect:write available
+xt:document available
+libxslt:debug available
+ === 3 Extension functions:
+libxslt:node-set() available
+saxon:node-set() available
+xt:node-set() available
+
diff --git a/tests/extensions/list.xml b/tests/extensions/list.xml
new file mode 100644 (file)
index 0000000..69d62f2
--- /dev/null
@@ -0,0 +1 @@
+<doc/>
diff --git a/tests/extensions/list.xsl b/tests/extensions/list.xsl
new file mode 100644 (file)
index 0000000..ffb03ba
--- /dev/null
@@ -0,0 +1,82 @@
+<?xml version='1.0'?>
+<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
+                xmlns:saxon="http://icl.com/saxon"
+               xmlns:xalanredirect="org.apache.xalan.xslt.extensions.Redirect"
+               xmlns:xt="http://www.jclark.com/xt"
+               xmlns:libxslt="http://xmlsoft.org/XSLT/namespace"
+                version='1.0'>
+
+<xsl:template match="/">
+<xsl:text> === 24 Standard elements:
+</xsl:text>
+<xsl:if test="element-available('xsl:apply-templates')">xsl:apply-templates available
+</xsl:if>
+<xsl:if test="element-available('xsl:apply-imports')">xsl:apply-imports available
+</xsl:if>
+<xsl:if test="element-available('xsl:call-template')">xsl:call-template available
+</xsl:if>
+<xsl:if test="element-available('xsl:element')">xsl:element available
+</xsl:if>
+<xsl:if test="element-available('xsl:attribute')">xsl:attribute available
+</xsl:if>
+<xsl:if test="element-available('xsl:text')">xsl:text available
+</xsl:if>
+<xsl:if test="element-available('xsl:processing-instruction')">xsl:processing-instruction available
+</xsl:if>
+<xsl:if test="element-available('xsl:comment')">xsl:comment available
+</xsl:if>
+<xsl:if test="element-available('xsl:copy')">xsl:copy available
+</xsl:if>
+<xsl:if test="element-available('xsl:value-of')">xsl:value-of available
+</xsl:if>
+<xsl:if test="element-available('xsl:number')">xsl:number available
+</xsl:if>
+<xsl:if test="element-available('xsl:for-each')">xsl:for-each available
+</xsl:if>
+<xsl:if test="element-available('xsl:if')">xsl:if available
+</xsl:if>
+<xsl:if test="element-available('xsl:choose')">xsl:choose available
+</xsl:if>
+<xsl:if test="element-available('xsl:sort')">xsl:sort available
+</xsl:if>
+<xsl:if test="element-available('xsl:copy-of')">xsl:copy-of available
+</xsl:if>
+<xsl:if test="element-available('xsl:message')">xsl:message available
+</xsl:if>
+<xsl:if test="element-available('xsl:variable')">xsl:variable available
+</xsl:if>
+<xsl:if test="element-available('xsl:param')">xsl:param available
+</xsl:if>
+<xsl:if test="element-available('xsl:with-param')">xsl:with-param available
+</xsl:if>
+<xsl:if test="element-available('xsl:decimal-format')">xsl:decimal-format available
+</xsl:if>
+<xsl:if test="element-available('xsl:when')">xsl:when available
+</xsl:if>
+<xsl:if test="element-available('xsl:otherwise')">xsl:otherwise available
+</xsl:if>
+<xsl:if test="element-available('xsl:fallback')">xsl:fallback available
+</xsl:if>
+<xsl:text> === 5 Extension elements:
+</xsl:text>
+<xsl:if test="element-available('xsl:element')">xsl:element available
+</xsl:if>
+<xsl:if test="element-available('saxon:output')">saxon:output available
+</xsl:if>
+<xsl:if test="element-available('xalanredirect:write')">xalanredirect:write available
+</xsl:if>
+<xsl:if test="element-available('xt:document')">xt:document available
+</xsl:if>
+<xsl:if test="element-available('libxslt:debug')">libxslt:debug available
+</xsl:if>
+<xsl:text> === 3 Extension functions:
+</xsl:text>
+<xsl:if test="function-available('libxslt:node-set')">libxslt:node-set() available
+</xsl:if>
+<xsl:if test="function-available('saxon:node-set')">saxon:node-set() available
+</xsl:if>
+<xsl:if test="function-available('xt:node-set')">xt:node-set() available
+</xsl:if>
+</xsl:template>
+
+</xsl:stylesheet>