Added Olivier's changes to support the document() function

This commit is contained in:
kvisco%ziplink.net 2000-05-24 03:46:31 +00:00
parent a57f63746a
commit 41954858e7
6 changed files with 77 additions and 24 deletions

View File

@ -28,14 +28,14 @@
* W3C XPath 1.0 Recommendation * W3C XPath 1.0 Recommendation
* -- Added lang attr declaration * -- Added lang attr declaration
* *
* $Id: Names.cpp,v 1.5 2000/05/23 08:13:03 kvisco%ziplink.net Exp $ * $Id: Names.cpp,v 1.6 2000/05/24 03:45:40 kvisco%ziplink.net Exp $
*/ */
/** /**
* XSL names used throughout the XSLProcessor. * XSL names used throughout the XSLProcessor.
* Probably should be wrapped in a Namespace * Probably should be wrapped in a Namespace
* @author <a href="mailto:kvisco@ziplink.net">Keith Visco</a> * @author <a href="mailto:kvisco@ziplink.net">Keith Visco</a>
* @version $Revision: 1.5 $ $Date: 2000/05/23 08:13:03 $ * @version $Revision: 1.6 $ $Date: 2000/05/24 03:45:40 $
**/ **/
#include "Names.h" #include "Names.h"
@ -149,11 +149,12 @@ const String NODE_FNAME = "node";
const String IDENTITY_OP = "."; const String IDENTITY_OP = ".";
const String PARENT_OP = ".."; const String PARENT_OP = "..";
//-- XSLT extension functions //-- XSLT additional functions
const String CURRENT_FN = "current"; const String CURRENT_FN = "current";
const String FORMAT_NUMBER_FN = "format-number"; const String FORMAT_NUMBER_FN = "format-number";
const String GENERATE_ID_FN = "generate-id"; const String GENERATE_ID_FN = "generate-id";
const String SYSTEM_PROPERTY_FN = "system-property"; const String SYSTEM_PROPERTY_FN = "system-property";
const String DOCUMENT_FN = "document";
//-- MISC //-- MISC
const String WILD_CARD = "*"; const String WILD_CARD = "*";

View File

@ -27,7 +27,7 @@
* W3C XPath 1.0 Recommendation * W3C XPath 1.0 Recommendation
* -- Added lang attr declaration * -- Added lang attr declaration
* $Id: Names.h,v 1.5 2000/05/23 08:13:03 kvisco%ziplink.net Exp $ * $Id: Names.h,v 1.6 2000/05/24 03:45:41 kvisco%ziplink.net Exp $
*/ */
#include "TxString.h" #include "TxString.h"
@ -144,11 +144,13 @@ extern const String NODE_FNAME;
extern const String IDENTITY_OP; extern const String IDENTITY_OP;
extern const String PARENT_OP; extern const String PARENT_OP;
//-- XSLT extension functions //-- XSLT additional functions
extern const String CURRENT_FN; extern const String CURRENT_FN;
extern const String FORMAT_NUMBER_FN; extern const String FORMAT_NUMBER_FN;
extern const String GENERATE_ID_FN; extern const String GENERATE_ID_FN;
extern const String SYSTEM_PROPERTY_FN; extern const String SYSTEM_PROPERTY_FN;
extern const String DOCUMENT_FN;
//-- MISC //-- MISC
extern const String WILD_CARD; extern const String WILD_CARD;

View File

@ -15,20 +15,23 @@
* Portions created by MITRE are Copyright (C) 1999 The MITRE Corporation. * Portions created by MITRE are Copyright (C) 1999 The MITRE Corporation.
* *
* Portions created by Keith Visco as a Non MITRE employee, * Portions created by Keith Visco as a Non MITRE employee,
* (C) 1999 Keith Visco. All Rights Reserved. * (C) 1999-2000 Keith Visco. All Rights Reserved.
* *
* Contributor(s): * Contributor(s):
* Keith Visco, kvisco@ziplink.net * Keith Visco, kvisco@ziplink.net
* -- original author. * -- original author.
* *
* $Id: ProcessorState.cpp,v 1.2 2000/04/19 10:41:13 kvisco%ziplink.net Exp $ * Olivier Gerardin, ogerardin@vo.lu
* -- added code in ::resolveFunctionCall to support the
* document() function.
*
* $Id: ProcessorState.cpp,v 1.3 2000/05/24 03:45:41 kvisco%ziplink.net Exp $
*/ */
/** /**
* Implementation of ProcessorState * Implementation of ProcessorState
* This code was ported from XSL:P * Much of this code was ported from XSL:P
* @author <a href="kvisco@ziplink.net">Keith Visco</a> * @version $Revision: 1.3 $ $Date: 2000/05/24 03:45:41 $
* @version $Revision: 1.2 $ $Date: 2000/04/19 10:41:13 $
**/ **/
#include "ProcessorState.h" #include "ProcessorState.h"
@ -587,6 +590,9 @@ FunctionCall* ProcessorState::resolveFunctionCall(const String& name) {
if (GENERATE_ID_FN.isEqual(name)) { if (GENERATE_ID_FN.isEqual(name)) {
return new GenerateIdFunctionCall(&domHelper); return new GenerateIdFunctionCall(&domHelper);
} }
else if (DOCUMENT_FN.isEqual(name)) {
return new DocumentFunctionCall(xslDocument);
}
String err("invalid function call: "); String err("invalid function call: ");
err.append(name); err.append(name);
@ -597,7 +603,7 @@ FunctionCall* ProcessorState::resolveFunctionCall(const String& name) {
/** /**
* Sorts the given NodeSet by DocumentOrder. * Sorts the given NodeSet by DocumentOrder.
* @param nodes the NodeSet to sort * @param nodes the NodeSet to sort
* <BR /> * <BR />
* <B>Note:</B> I will be moving this functionality elsewhere soon * <B>Note:</B> I will be moving this functionality elsewhere soon
@ -625,7 +631,7 @@ void ProcessorState::sortByDocumentOrder(NodeSet* nodes) {
} }
nodes->clear(); nodes->clear();
for (i = 0; i < sorted.size(); i++) for (i = 0; i < sorted.size(); i++)
nodes->add(sorted.get(i)); nodes->add(sorted.get(i));
sorted.clear(); sorted.clear();

View File

@ -2,29 +2,39 @@
ROOT = ../.. ROOT = ../..
BASE = $(ROOT)/base BASE = $(ROOT)/base
NET = $(ROOT)/net
XPATH = $(ROOT)/xpath XPATH = $(ROOT)/xpath
XML = $(ROOT)/xml XML = $(ROOT)/xml
XML_UTIL = $(XML)/util XML_UTIL = $(XML)/util
DOM = $(XML)/dom DOM = $(XML)/dom
XSLT = $(ROOT)/xslt XSLT = $(ROOT)/xslt
XMLPARSER_PATH = $(XML)/parser
EXPAT_PARSER_PATH = $(XMLPARSER_PATH)/xmlparse
ALL_OBJS = \ ALL_OBJS = \
GenerateIdFunctionCall.o GenerateIdFunctionCall.o \
DocumentFunctionCall.o
INCLUDE_PATH = -I. \ INCLUDE_PATH = -I. \
-I$(BASE) \ -I$(BASE) \
-I$(NET) \
-I$(XPATH) \ -I$(XPATH) \
-I$(XML) \ -I$(XML) \
-I$(XML)/parser \
-I$(XML_UTIL) \ -I$(XML_UTIL) \
-I$(DOM) \ -I$(DOM) \
-I$(XSLT) \ -I$(XSLT) \
-I$(XSLT)/util -I$(XSLT)/util \
-I$(EXPAT_PARSER_PATH)
target: $(ALL_OBJS) target: $(ALL_OBJS)
GenerateIdFunctionCall.o: XSLTFunctions.h GenerateIdFunctionCall.cpp GenerateIdFunctionCall.o: XSLTFunctions.h GenerateIdFunctionCall.cpp
$(CC) $(INCLUDE_PATH) -c GenerateIdFunctionCall.cpp $(CC) $(INCLUDE_PATH) -c GenerateIdFunctionCall.cpp
DocumentFunctionCall.o: XSLTFunctions.h DocumentFunctionCall.cpp
$(CC) $(INCLUDE_PATH) -c DocumentFunctionCall.cpp

View File

@ -1,23 +1,23 @@
# #
# The contents of this file are subject to the Mozilla Public # The contents of this file are subject to the Mozilla Public
# License Version 1.1 (the "License"); you may not use this file # License Version 1.1 (the "License"); you may not use this file
# except in compliance with the License. You may obtain a copy of # except in compliance with the License. You may obtain a copy of
# the License at http://www.mozilla.org/MPL/ # the License at http://www.mozilla.org/MPL/
# #
# Software distributed under the License is distributed on an "AS # Software distributed under the License is distributed on an "AS
# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or # IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
# implied. See the License for the specific language governing # implied. See the License for the specific language governing
# rights and limitations under the License. # rights and limitations under the License.
# #
# The Original Code is Transformiix XSLT Processor. # The Original Code is Transformiix XSLT Processor.
# #
# The Initial Developer of the Original Code is Axel Hecht. # The Initial Developer of the Original Code is Axel Hecht.
# Portions created by Axel Hecht are Copyright (C) Axel Hecht. # Portions created by Axel Hecht are Copyright (C) Axel Hecht.
# All Rights Reserved. # All Rights Reserved.
# #
# Contributor(s): # Contributor(s):
# Axel Hecht <axel@pike.org> # Axel Hecht <axel@pike.org>
# #
DEPTH = ../../../../.. DEPTH = ../../../../..
topsrcdir = @top_srcdir@ topsrcdir = @top_srcdir@
@ -26,7 +26,8 @@ VPATH = @srcdir@
include $(DEPTH)/config/autoconf.mk include $(DEPTH)/config/autoconf.mk
CPPSRCS = GenerateIdFunctionCall.cpp CPPSRCS = GenerateIdFunctionCall.cpp \
DocumentFunctionCall.cpp
include $(topsrcdir)/config/rules.mk include $(topsrcdir)/config/rules.mk
@ -34,4 +35,4 @@ INCLUDES += -I$(srcdir)/../../base -I$(srcdir)/../../xpath \
-I$(srcdir)/../../xml -I$(srcdir)/../../xml/util -I$(srcdir)/../../xml/dom \ -I$(srcdir)/../../xml -I$(srcdir)/../../xml/util -I$(srcdir)/../../xml/dom \
-I$(srcdir)/../../xslt -I$(srcdir)/../../xslt
install:: $(OBJS) install:: $(OBJS)

View File

@ -20,7 +20,10 @@
* Keith Visco, kvisco@ziplink.net * Keith Visco, kvisco@ziplink.net
* -- original author. * -- original author.
* *
* $Id: XSLTFunctions.h,v 1.1 2000/04/19 10:40:06 kvisco%ziplink.net Exp $ * Olivier Gerardin,
* -- added document() function definition
*
* $Id: XSLTFunctions.h,v 1.2 2000/05/24 03:46:31 kvisco%ziplink.net Exp $
*/ */
#include "dom.h" #include "dom.h"
@ -33,6 +36,9 @@
#ifndef TRANSFRMX_XSLT_FUNCTIONS_H #ifndef TRANSFRMX_XSLT_FUNCTIONS_H
#define TRANSFRMX_XSLT_FUNCTIONS_H #define TRANSFRMX_XSLT_FUNCTIONS_H
/**
* The definition for the XSLT generate-id() function
**/
class GenerateIdFunctionCall : public FunctionCall { class GenerateIdFunctionCall : public FunctionCall {
public: public:
@ -56,4 +62,31 @@ private:
DOMHelper* domHelper; DOMHelper* domHelper;
}; };
#endif /**
* The definition for the XSLT document() function
**/
class DocumentFunctionCall : public FunctionCall {
public:
/**
* Creates a new document() function call
**/
DocumentFunctionCall(Document* xslDocument);
/**
* Evaluates this Expr based on the given context node and processor state
* @param context the context node for evaluation of this Expr
* @param ps the ContextState containing the stack information needed
* for evaluation
* @return the result of the evaluation
* @see FunctionCall.h
**/
virtual ExprResult* evaluate(Node* context, ContextState* cs);
private:
void retrieveDocument(String& uri,String& baseUri, NodeSet &resultNodeSet, ContextState* cs);
Document* xslDocument;
};
#endif