summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog9
-rw-r--r--libxslt/extra.c2
-rw-r--r--libxslt/functions.c35
-rw-r--r--libxslt/transform.c64
-rw-r--r--libxslt/transform.h2
-rw-r--r--libxslt/variables.h1
-rw-r--r--tests/extensions/Makefile.am3
-rw-r--r--tests/extensions/list.out37
-rw-r--r--tests/extensions/list.xml1
-rw-r--r--tests/extensions/list.xsl82
10 files changed, 232 insertions, 4 deletions
diff --git a/ChangeLog b/ChangeLog
index 157caf7e..ba22f580 100644
--- 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'
diff --git a/libxslt/extra.c b/libxslt/extra.c
index 223e3d9f..17f82087 100644
--- a/libxslt/extra.c
+++ b/libxslt/extra.c
@@ -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);
}
diff --git a/libxslt/functions.c b/libxslt/functions.c
index 3c66905d..a4bc1c1e 100644
--- a/libxslt/functions.c
+++ b/libxslt/functions.c
@@ -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);
}
/**
diff --git a/libxslt/transform.c b/libxslt/transform.c
index 315145ca..b1096f17 100644
--- a/libxslt/transform.c
+++ b/libxslt/transform.c
@@ -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);
+
+}
diff --git a/libxslt/transform.h b/libxslt/transform.h
index 4406751a..dd4b3e96 100644
--- a/libxslt/transform.h
+++ b/libxslt/transform.h
@@ -112,7 +112,7 @@ void xsltForEach (xsltTransformContextPtr ctxt,
xmlNodePtr node,
xmlNodePtr inst,
xsltStylePreCompPtr comp);
-
+void xsltRegisterAllElement (xsltTransformContextPtr ctxt);
#ifdef __cplusplus
}
#endif
diff --git a/libxslt/variables.h b/libxslt/variables.h
index 2cdafd05..135b4280 100644
--- a/libxslt/variables.h
+++ b/libxslt/variables.h
@@ -29,6 +29,7 @@ extern "C" {
xmlXPathRegisterVariableLookup((ctxt)->xpathCtxt, \
xsltXPathVariableLookup, (void *)(ctxt)); \
xsltRegisterAllFunctions((ctxt)->xpathCtxt); \
+ xsltRegisterAllElement(ctxt); \
(ctxt)->xpathCtxt->extra = ctxt
/*
diff --git a/tests/extensions/Makefile.am b/tests/extensions/Makefile.am
index 2bf71a93..8db24e26 100644
--- a/tests/extensions/Makefile.am
+++ b/tests/extensions/Makefile.am
@@ -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
index 00000000..44843632
--- /dev/null
+++ b/tests/extensions/list.out
@@ -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
index 00000000..69d62f2c
--- /dev/null
+++ b/tests/extensions/list.xml
@@ -0,0 +1 @@
+<doc/>
diff --git a/tests/extensions/list.xsl b/tests/extensions/list.xsl
new file mode 100644
index 00000000..ffb03bad
--- /dev/null
+++ b/tests/extensions/list.xsl
@@ -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>