This commit is contained in:
kvisco%ziplink.net 1999-11-18 04:40:02 +00:00
Родитель a6b00e810f
Коммит 719073de41
22 изменённых файлов: 2830 добавлений и 2116 удалений

Разница между файлами не показана из-за своего большого размера Загрузить разницу

Просмотреть файл

@ -1,12 +1,12 @@
<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="functions.xsl"?>
<!-- this is a test document -->
<document>
<!-- test comment -->
<x name="x">x</x>
<y name="y">y</y>
<z name="z">z</z>
<names>
<abc:test-name/>
</names>
</document>
<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="functions.xsl"?>
<!-- this is a test document -->
<document>
<!-- test comment -->
<x name="x">x</x>
<y name="y">y</y>
<z name="z">z</z>
<names>
<abc:test-name/>
</names>
</document>

Разница между файлами не показана из-за своего большого размера Загрузить разницу

Просмотреть файл

@ -1,8 +0,0 @@
<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="identity.xsl"?>
<document>
<x name="x">x</x>
<y name="y">y</y>
<z name="z">z</z>
</document>

Просмотреть файл

@ -1,13 +0,0 @@
<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="test.xsl"?>
<!-- this is a test document -->
<document>
<!-- test comment -->
<x name="x">x</x>
<y name="y">y</y>
<z name="z">z</z>
<abc>
<def>def</def>
</abc>
</document>

Просмотреть файл

@ -1,33 +1,38 @@
<?xml version="1.0"?>
<!--
/*
* (C) Copyright The MITRE Corporation 1999 All rights reserved.
* The contents of this file are subject to the Mozilla Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is XSL:P XSLT processor.
*
* The Initial Developer of the Original Code is Keith Visco.
* Portions created by Keith Visco (C) 1999 Keith Visco.
* All Rights Reserved..
*
* The contents of this file are subject to the Mozilla Public License
* Version 1.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* The program provided "as is" without any warranty express or
* implied, including the warranty of non-infringement and the implied
* warranties of merchantibility and fitness for a particular purpose.
* The Copyright owner will not be liable for any damages suffered by
* you as a result of using the Program. In no event will the Copyright
* owner be liable for any special, indirect or consequential damages or
* lost profits even if the Copyright owner has been advised of the
* possibility of their occurrence.
*
* Please see release.txt distributed with this file for more information.
* Contributor(s):
* Keith Visco, kvisco@ziplink.net
* - original author.
*
* $Id: test.xsl,v 1.3 1999-11-18 04:39:51 kvisco%ziplink.net Exp $
*/
/**
* This is a test stylesheet used for testing MITRE's XSL processor
**/
-->
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/XSL/Transform/1.0"
result-ns="http://www.w3.org/TR/REC-html40">
<!--
This is a test stylesheet used for testing the XSL processor
-->
<xsl:stylesheet xmlns:xsl="http://www.w3.org/XSL/Transform/1.0">
<!-- set the output properties -->
<xsl:output method="html"/>
<!-- AttributeSet -->
<xsl:attribute-set name="style1">
@ -45,7 +50,7 @@
<xsl:processing-instruction name="foo">
this is a test processing instruction
</xsl:processing-instruction>
<xsl:comment>MITRE TransforMiiX Test cases, written by Keith Visco.</xsl:comment>
<xsl:comment>TransforMiiX Test cases, written by Keith Visco.</xsl:comment>
<xsl:apply-templates/>
</xsl:template>
@ -73,12 +78,28 @@
<xsl:template match="document">
<HTML>
<HEAD>
<TITLE>MII TransforMiiX Test Cases</TITLE>
<TITLE>TransforMiiX Test Cases</TITLE>
<SCRIPT Language="JavaScript">
<xsl:text>
// This is a test for properly printing SCRIPT elements
// currently there is a bug, so use xsl:text as a wrapper as I
// have done here
function foo() {
var x = 1;
var y = 2;
return (x &lt; y);
}
//
</xsl:text>
</SCRIPT>
</HEAD>
<BODY>
<BODY BGColor="#FFFFFF" Text="#000000">
<CENTER>
<FONT COLOR="BLUE" FACE="Arial"><B>MITRE</B></FONT><BR/>
<B>MII Transfor<FONT COLOR="blue">Mii</FONT>X Test Cases</B>
<FONT COLOR="BLUE" FACE="Arial" SIZE="+1">
<B>Mozilla XSLT</B>
</FONT>
<BR/>
<B>Transfor<FONT COLOR="blue">Mii</FONT>X Test Cases</B>
</CENTER>
<P>
This document serves to test basic XSL expressions.

Просмотреть файл

@ -1,26 +0,0 @@
EXPAT_PARSER_PATH = xmlparse
EXPAT_TOKEN_PATH = xmltok
EXPAT_OBJS = $(EXPAT_TOKEN_PATH)/xmltok.o \
$(EXPAT_TOKEN_PATH)/xmlrole.o \
$(EXPAT_PARSER_PATH)/xmlparse.o \
$(EXPAT_PARSER_PATH)/hashtable.o
INCLUDE_PATH = -I. -I$(EXPAT_PARSER_PATH) -I$(EXPAT_TOKEN_PATH) -I-
FLAGS = -DXML_UNICODE
CC := cc -g $(FLAGS) $(INCLUDE_PATH)
target: $(EXPAT_OBJS)
xmltok.o xmlrole.o:
cd $(EXPAT_TOKEN_PATH); \
$(CC) -c xmltok.c xmlrole.c
xmlparse.o hashtable.o:
cd $(EXPAT_PARSER_PATH); \
$(CC) -c xmlparse.c hashtable.c

Просмотреть файл

@ -19,7 +19,9 @@
* Keith Visco, kvisco@ziplink.net
* -- original author
*
* $Id: HTMLPrinter.cpp,v 1.2 1999-11-15 07:13:00 nisheeth%netscape.com Exp $
* Michel Casabianca, casa@sdv.fr
* -- added additional empty elements to the HTML tag list
* $Id: HTMLPrinter.cpp,v 1.3 1999-11-18 04:39:54 kvisco%ziplink.net Exp $
*/
#include "printers.h"
@ -32,7 +34,7 @@
* A class for printing XML nodes.
* This class was ported from XSL:P Java source
* @author <a href="kvisco@ziplink.net">Keith Visco</a>
* @version $Revision: 1.2 $ $Date: 1999-11-15 07:13:00 $
* @version $Revision: 1.3 $ $Date: 1999-11-18 04:39:54 $
**/
//---------------/
//- Contructors -/
@ -69,13 +71,21 @@ void HTMLPrinter::initialize(ostream& os, int indentSize) {
setUseFormat(MB_TRUE);
MITREObject* nonNull = &htmlEmptyTags;
htmlEmptyTags.put("AREA", nonNull);
htmlEmptyTags.put("BASE", nonNull);
htmlEmptyTags.put("BASEFONT", nonNull);
htmlEmptyTags.put("BR", nonNull);
htmlEmptyTags.put("HR", nonNull);
htmlEmptyTags.put("FRAME", nonNull);
htmlEmptyTags.put("HR", nonNull);
htmlEmptyTags.put("IMAGE", nonNull);
htmlEmptyTags.put("IMG", nonNull);
htmlEmptyTags.put("INPUT", nonNull);
htmlEmptyTags.put("ISINDEX", nonNull);
htmlEmptyTags.put("LI", nonNull);
htmlEmptyTags.put("LINK", nonNull);
htmlEmptyTags.put("META", nonNull);
htmlEmptyTags.put("P", nonNull);
htmlEmptyTags.put("PARAM", nonNull);
} //-- initialize
@ -132,8 +142,70 @@ MBool HTMLPrinter::print(Node* node, String& currentIndent) {
String nodeName = node->getNodeName();
nodeName.toUpperCase();
//-- ALL THIS CODE WILL BE CHANGING I AM CURRENTLY
//-- WRITING THE SAX-LIKE PRINTER, WHICH WILL BE USED
//-- BY THIS PRINTER
if (nodeName.isEqual("SCRIPT")) {
Element* element = (Element*)node;
out << L_ANGLE_BRACKET;
out << nodeName;
NamedNodeMap* attList = element->getAttributes();
int size = 0;
if (attList) size = attList->getLength();
Attr* att = 0;
int i = 0;
for ( ; i < size; i++) {
att = (Attr*) attList->item(i);
out << SPACE;
out << att->getName();
const DOMString& data = att->getValue();
if (&data != &NULL_STRING) {
out << EQUALS << DOUBLE_QUOTE;
out << data;
out << DOUBLE_QUOTE;
}
}
out << R_ANGLE_BRACKET;
NodeList* nl = element->getChildNodes();
if (useFormat) out<<endl;
for (i = 0; i < nl->getLength(); i++) {
Node* child = nl->item(i);
switch(child->getNodeType()) {
case Node::COMMENT_NODE:
{
out << COMMENT_START;
out << ((CharacterData*)child)->getData();
out << COMMENT_END;
break;
}
case Node::TEXT_NODE:
case Node::CDATA_SECTION_NODE:
{
out << ((Text*)child)->getData();
break;
}
default:
break;
}
}
out << flush;
if (useFormat) {
out << endl << currentIndent;
}
out << L_ANGLE_BRACKET << FORWARD_SLASH;
out << nodeName;
out << R_ANGLE_BRACKET;
if (useFormat) {
out << endl;
return MB_TRUE;
}
return MB_FALSE;
}
//-- handle special elements
if (node->hasChildNodes() || ( !htmlEmptyTags.get(nodeName) )) {
else if (node->hasChildNodes() ||
( !htmlEmptyTags.get(nodeName)))
{
return XMLPrinter::print(node, currentIndent);
}
else {

Просмотреть файл

@ -1,23 +1,27 @@
/*
* (C) Copyright The MITRE Corporation 1999 All rights reserved.
* The contents of this file are subject to the Mozilla Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is TransforMiiX XSLT processor.
*
* The Initial Developer of the Original Code is The MITRE Corporation.
* Portions created by MITRE are Copyright (C) 1999 The MITRE Corporation.
*
* The contents of this file are subject to the Mozilla Public License
* Version 1.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
* Portions created by Keith Visco as a Non MITRE employee,
* (C) 1999 Keith Visco. All Rights Reserved.
*
* Contributor(s):
* Keith Visco, kvisco@ziplink.net
* -- original author.
*
* The program provided "as is" without any warranty express or
* implied, including the warranty of non-infringement and the implied
* warranties of merchantibility and fitness for a particular purpose.
* The Copyright owner will not be liable for any damages suffered by
* you as a result of using the Program. In no event will the Copyright
* owner be liable for any special, indirect or consequential damages or
* lost profits even if the Copyright owner has been advised of the
* possibility of their occurrence.
*
* Please see release.txt distributed with this file for more information.
*
* $Id: printers.h,v 1.1 1999-11-15 07:28:00 nisheeth%netscape.com Exp $
* $Id: printers.h,v 1.2 1999-11-18 04:39:54 kvisco%ziplink.net Exp $
*/
@ -27,15 +31,15 @@
#include "NamedMap.h"
#include <iostream.h>
#ifndef MITRE_PRINTERS_H
#define MITRE_PRINTERS_H
#ifndef TRANSFRMX_PRINTERS_H
#define TRANSFRMX_PRINTERS_H
/**
* A class for printing XML nodes.
* This class was ported from XSL:P Java source
* @author <a href="mailto:kvisco@ziplink.net">Keith Visco</a>
* @version $Revision: 1.1 $ $Date: 1999-11-15 07:28:00 $
* @version $Revision: 1.2 $ $Date: 1999-11-18 04:39:54 $
**/
class XMLPrinter {
@ -232,7 +236,7 @@ private:
* A class for printing an XML node as non-well-formed HTML
* This class was ported from XSL:P Java source
* @author Keith Visco (kvisco@ziplink.net)
* @version $Revision: 1.1 $ $Date: 1999-11-15 07:28:00 $
* @version $Revision: 1.2 $ $Date: 1999-11-18 04:39:54 $
**/
class HTMLPrinter : public XMLPrinter {

Просмотреть файл

@ -2,7 +2,7 @@ target: xslp
CC := $(CC) -g
#ifndef PROJ_PATH
ROOT_PATH = ..
XML_PATH = $(ROOT_PATH)/xml
XSL_PATH = $(ROOT_PATH)/xsl
@ -15,7 +15,7 @@ XMLPRINTER_PATH = $(XML_PATH)/printer
XMLPARSER_PATH = $(XML_PATH)/parser
EXPAT_PARSER_PATH = $(XMLPARSER_PATH)/xmlparse
EXPAT_TOKEN_PATH = $(XMLPARSER_PATH)/xmltok
#endif
INCLUDE_PATHS = -I$(BASE_PATH) \
-I$(NET_PATH) \
@ -30,6 +30,7 @@ INCLUDE_PATHS = -I$(BASE_PATH) \
XSL_OBJS = Names.o \
Numbering.o \
OutputFormat.o \
ProcessorState.o \
VariableBinding.o \
XSLProcessor.o
@ -46,6 +47,9 @@ Names.o: Names.cpp Names.h
Numbering.o: Numbering.cpp Numbering.h
$(CC) $(INCLUDE_PATHS) -c Numbering.cpp
OutputFormat.o: OutputFormat.cpp OutputFormat.h
$(CC) $(INCLUDE_PATHS) -c OutputFormat.cpp
ProcessorState.o: ProcessorState.cpp ProcessorState.h
$(CC) $(INCLUDE_PATHS) -c ProcessorState.cpp
@ -53,4 +57,4 @@ VariableBinding.o: VariableBinding.h VariableBinding.cpp
$(CC) $(INCLUDE_PATHS) -c VariableBinding.cpp
XSLProcessor.o: XSLProcessor.cpp XSLProcessor.h
$(CC) -c XSLProcessor.cpp -D __cplusplus $(INCLUDE_PATHS)
$(CC) -c XSLProcessor.cpp -D__cplusplus $(INCLUDE_PATHS)

Просмотреть файл

@ -21,14 +21,14 @@
* Keith Visco, kvisco@ziplink.net
* -- original author.
*
* $Id: Names.cpp,v 1.2 1999-11-15 07:13:07 nisheeth%netscape.com Exp $
* $Id: Names.cpp,v 1.3 1999-11-18 04:39:55 kvisco%ziplink.net Exp $
*/
/**
* XSL names used throughout the XSLProcessor.
* Probably should be wrapped in a Namespace
* @author <a href="mailto:kvisco@ziplink.net">Keith Visco</a>
* @version $Revision: 1.2 $ $Date: 1999-11-15 07:13:07 $
* @version $Revision: 1.3 $ $Date: 1999-11-18 04:39:55 $
**/
#include "Names.h"
@ -59,6 +59,7 @@ const String INCLUDE = "include";
const String MESSAGE = "message";
const String NUMBER = "number";
const String OTHERWISE = "otherwise";
const String OUTPUT = "output";
const String PARAM = "param";
const String PI = "processing-instruction";
const String PRESERVE_SPACE = "preserve-space";
@ -72,23 +73,34 @@ const String WITH_PARAM = "with-param";
//-- Attributes
const String CDATA_ELEMENTS_ATTR = "cdata-section-elements";
const String COUNT_ATTR = "count";
const String DEFAULT_SPACE_ATTR = "default-space";
const String DOCTYPE_PUBLIC_ATTR = "doctype-public";
const String DOCTYPE_SYSTEM_ATTR = "doctype-system";
const String ELEMENTS_ATTR = "elements";
const String ENCODING_ATTR = "encoding";
const String EXPR_ATTR = "expr";
const String FORMAT_ATTR = "format";
const String FROM_ATTR = "from";
const String HREF_ATTR = "href";
const String INDENT_ATTR = "indent";
const String LEVEL_ATTR = "level";
const String MATCH_ATTR = "match";
const String METHOD_ATTR = "method";
const String MEDIA_TYPE_ATTR = "media-type";
const String MODE_ATTR = "mode";
const String NAME_ATTR = "name";
const String NAMESPACE_ATTR = "namespace";
const String OMIT_XMLDECL_ATTR = "omit-xml-declaration";
const String PRIORITY_ATTR = "priority";
const String SELECT_ATTR = "select";
const String STANDALONE = "standalone";
const String TEST_ATTR = "test";
const String USE_ATTRIBUTE_SETS_ATTR = "use-attribute-sets";
const String VALUE_ATTR = "value";
const String VERSION_ATTR = "version";
//-- Attribute Values
const String ANY_VALUE = "any";

Просмотреть файл

@ -21,13 +21,13 @@
* Keith Visco, kvisco@ziplink.net
* -- original author.
*
* $Id: Names.h,v 1.2 1999-11-15 07:13:07 nisheeth%netscape.com Exp $
* $Id: Names.h,v 1.3 1999-11-18 04:39:56 kvisco%ziplink.net Exp $
*/
#include "String.h"
#ifndef MITREXSL_NAMES_H
#define MITREXSL_NAMES_H
#ifndef TRANSFRMX_NAMES_H
#define TRANSFRMX_NAMES_H
//-- Global Strings
extern const String HTML;
@ -56,6 +56,7 @@ extern const String INCLUDE;
extern const String MESSAGE;
extern const String NUMBER;
extern const String OTHERWISE;
extern const String OUTPUT;
extern const String PARAM;
extern const String PI;
extern const String PRESERVE_SPACE;
@ -69,23 +70,33 @@ extern const String WITH_PARAM;
//-- Attributes
extern const String CDATA_ELEMENTS;
extern const String COUNT_ATTR;
extern const String DEFAULT_SPACE_ATTR;
extern const String DOCTYPE_PUBLIC_ATTR;
extern const String DOCTYPE_SYSTEM_ATTR;
extern const String ELEMENTS_ATTR;
extern const String ENCODING_ATTR;
extern const String EXPR_ATTR;
extern const String FORMAT_ATTR;
extern const String FROM_ATTR;
extern const String HREF_ATTR;
extern const String INDENT_ATTR;
extern const String LEVEL_ATTR;
extern const String MATCH_ATTR;
extern const String MEDIA_TYPE_ATTR;
extern const String METHOD_ATTR;
extern const String MODE_ATTR;
extern const String NAME_ATTR;
extern const String NAMESPACE_ATTR;
extern const String OMIT_XMLDECL_ATTR;
extern const String PRIORITY_ATTR;
extern const String SELECT_ATTR;
extern const String STANDALONE;
extern const String TEST_ATTR;
extern const String USE_ATTRIBUTE_SETS_ATTR;
extern const String VALUE_ATTR;
extern const String VERSION_ATTR;
//-- Attribute Values
extern const String ANY_VALUE;

Просмотреть файл

@ -0,0 +1,227 @@
/*
* The contents of this file are subject to the Mozilla Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is XSL:P XSLT processor.
*
* The Initial Developer of the Original Code is Keith Visco.
* Portions created by Keith Visco (C) 1999 Keith Visco.
* All Rights Reserved..
*
* Contributor(s):
* Keith Visco, kvisco@ziplink.net
* -- original author.
*
* $Id: OutputFormat.cpp,v 1.1 1999-11-18 04:39:56 kvisco%ziplink.net Exp $
*/
#include "OutputFormat.h"
/**
* @author <a href="mailto:kvisco@ziplink.net">Keith Visco</a>
* @version $Revision: 1.1 $ $Date: 1999-11-18 04:39:56 $
**/
/**
* Creates a new OutputFormat with the default values.
**/
OutputFormat::OutputFormat() {
method.append("xml");
explicitMethod = MB_FALSE;
explicitIndent = MB_FALSE;
indent = MB_FALSE;
} //-- OutputFormat
/**
* Deletes this OutputFormat
**/
OutputFormat::~OutputFormat() {};
/**
* Returns the publicId for use when creating a DOCTYPE in the output.
* @param dest the destination String to set equal to the value of the
* public identifier.
* @return the dest String containing the public identifier
**/
String& OutputFormat::getDoctypePublic(String& dest) {
dest.clear();
dest.append(publicId);
return dest;
} //-- getDoctypePublic
/**
* Returns the systemId for use when creating a DOCTYPE in the output.
* @param dest the destination String to set equal to the value of the
* system identifier.
* @return the dest String containing the system identifier
**/
String& OutputFormat::getDoctypeSystem(String& dest) {
dest.clear();
dest.append(systemId);
return dest;
} //-- getDoctypeSystem
/**
* Gets the XML output encoding that should be use when serializing
* XML documents,and appends it to the destination String.
* The destination String will be cleared before the encoding is
* appended.
* @param dest the String to append the output encoding to
* @return the given dest String now containing the output encoding
**/
String& OutputFormat::getEncoding(String& dest) {
dest.clear();
dest.append(encoding);
return dest;
} //-- getEncoding
/**
* @return whether or not indentation is allowed during serialization of
* XML or HTML documents. If this value is not explicitly set using
* ::setIndent, then a default indent flag is calculated based on
* the value of the output method. By default "xml" output method will
* return a value of MB_FALSE, while "html" output is MB_TRUE.
**/
MBool OutputFormat::getIndent() {
if (explicitIndent) return indent;
if (method.isEqual("html")) return MB_TRUE;
return MB_FALSE;
} //-- getIndent
/**
* Gets the output method and appends it to the destination String.
* The destination String will be cleared before the method is
* appended.
* @param dest the String to append the output method to
* @return the given dest String now containing the output method
**/
String& OutputFormat::getMethod(String& dest) {
dest.clear();
dest.append(method);
return dest;
} //-- getMethod
/**
* Gets the XML output version that should be used when serializing
* XML documents,and appends it to the destination String.
* The destination String will be cleared before the version is
* appended.
* @param dest the String to append the output version to
* @return the given dest String now containing the output version
**/
String& OutputFormat::getVersion(String& dest) {
dest.clear();
dest.append(version);
return dest;
}
/**
* @return true if the output method is equal to "html".
**/
MBool OutputFormat::isHTMLOutput() {
return (MBool) method.isEqual("html");
} //-- isHTMLOutput
/**
* @return true if allowing indentation was explicitly specified.
**/
MBool OutputFormat::isIndentExplicit() {
return explicitIndent;
} //-- isIndentExplicit
/**
* @return true if the output method was explicitly specified.
**/
MBool OutputFormat::isMethodExplicit() {
return explicitMethod;
} //-- isMethodExplicit
/**
* @return true if the output method is equal to "text".
**/
MBool OutputFormat::isTextOutput() {
return (MBool) method.isEqual("text");
} //-- isTextOuput
/**
* @return true if the output method is equal to "xml".
**/
MBool OutputFormat::isXMLOutput() {
return (MBool) method.isEqual("xml");
} //-- isXMLOutput
/**
* Sets the publicId for use when creating a DOCTYPE in the output.
* @param publicId the value of the DOCTYPE's public identifier..
**/
void OutputFormat::setDoctypePublic(const String& publicId) {
this->publicId = publicId;
} //-- setDoctypePublic
/**
* Sets the systemId for use when creating a DOCTYPE in the output.
* @param systemId the value of the DOCTYPE's system identifier..
**/
void OutputFormat::setDoctypeSystem(const String& systemId) {
this->systemId = systemId;
} //-- setDoctypeSystem
/**
* Sets the xml output encoding that should be used when serializing
* XML documents.
* @param encoding the value to set the XML output encoding to.
**/
void OutputFormat::setEncoding(const String& encoding) {
this->encoding = encoding;
} //-- setEncoding
/**
* Sets whether or not indentation is allowed during serialization
* @param allowIndentation the flag that specifies whether or not
* indentation is allowed during serialization
**/
void OutputFormat::setIndent(MBool allowIndentation) {
explicitIndent = MB_TRUE;
indent = allowIndentation;
} //-- setIndent
/**
* Sets the output method. Valid output method options are,
* "xml", "html", or "text".
* @param method the value to set the XML output method to. If
* the given String is not a valid method, the method will be
* set to "xml".
**/
void OutputFormat::setMethod(const String& method) {
explicitMethod = MB_TRUE;
if (method.isEqual("html")) this->method = method;
else if (method.isEqual("text")) this->method = method;
else this->method = "xml";
} //-- setMethod
/**
* Sets the xml output version that should be used when serializing
* XML documents.
* @param version the value to set the XML output version to.
**/
void OutputFormat::setVersion(const String& version) {
this->version = version;
} //-- setVersion

Просмотреть файл

@ -0,0 +1,203 @@
/*
* The contents of this file are subject to the Mozilla Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is XSL:P XSLT processor.
*
* The Initial Developer of the Original Code is Keith Visco.
* Portions created by Keith Visco (C) 1999 Keith Visco.
* All Rights Reserved..
*
* Contributor(s):
* Keith Visco, kvisco@ziplink.net
* -- original author.
*
* $Id: OutputFormat.h,v 1.1 1999-11-18 04:39:57 kvisco%ziplink.net Exp $
*/
#ifndef TRANSFRMX_OUTPUTFORMAT_H
#define TRANSFRMX_OUTPUTFORMAT_H
#include "String.h"
#include "baseutils.h"
/**
* @author <a href="mailto:kvisco@ziplink.net">Keith Visco</a>
* @version $Revision: 1.1 $ $Date: 1999-11-18 04:39:57 $
**/
class OutputFormat {
public:
/**
* Creates a new OutputFormat with the default values.
**/
OutputFormat();
/**
* Deletes this OutputFormat
**/
virtual ~OutputFormat();
/**
* Returns the publicId for use when creating a DOCTYPE in the output.
* @param dest the destination String to set equal to the value of the
* public identifier.
* @return the dest String containing the public identifier
**/
String& getDoctypePublic(String& dest);
/**
* Returns the systemId for use when creating a DOCTYPE in the output.
* @param dest the destination String to set equal to the value of the
* system identifier.
* @return the dest String containing the system identifier
**/
String& getDoctypeSystem(String& dest);
/**
* Gets the XML output encoding that should be use when serializing
* XML documents,and appends it to the destination String.
* The destination String will be cleared before the encoding is
* appended.
* @param dest the String to append the output encoding to
* @return the given dest String now containing the output encoding
**/
String& getEncoding(String& dest);
/**
* @return whether or not indentation is allowed during serialization of
* XML or HTML documents. If this value is not explicitly set using
* ::setIndent, then a default indent flag is calculated based on
* the value of the output method. By default "xml" output method will
* return a value of MB_FALSE, while "html" output is MB_TRUE.
**/
MBool getIndent();
/**
* Gets the output method and appends it to the destination String.
* The destination String will be cleared before the method is
* appended.
* @param dest the String to append the output method to
* @return the given dest String now containing the output method
**/
String& getMethod(String& dest);
/**
* Gets the XML output version that should be used when serializing
* XML documents,and appends it to the destination String.
* The destination String will be cleared before the version is
* appended.
* @param dest the String to append the output version to
* @return the given dest String now containing the output version
**/
String& getVersion(String& dest);
/**
* @return true if the output method is equal to "html".
**/
MBool isHTMLOutput();
/**
* @return true if allowing indentation was explicitly specified.
**/
MBool isIndentExplicit();
/**
* @return true if the output method was explicitly specified.
**/
MBool isMethodExplicit();
/**
* @return true if the output method is equal to "xml".
**/
MBool isXMLOutput();
/**
* @return true if the output method is equal to "text".
**/
MBool isTextOutput();
/**
* Sets the publicId for use when creating a DOCTYPE in the output.
* @param publicId the value of the DOCTYPE's public identifier..
**/
void setDoctypePublic(const String& publicId);
/**
* Sets the systemId for use when creating a DOCTYPE in the output.
* @param systemId the value of the DOCTYPE's system identifier..
**/
void setDoctypeSystem(const String& publicId);
/**
* Sets the xml output encoding that should be used when serializing
* XML documents.
* @param encoding the value to set the XML output encoding to.
**/
void setEncoding(const String& encoding);
/**
* Sets whether or not indentation is allowed during serialization
* @param allowIndentation the flag that specifies whether or not
* indentation is allowed during serialization
**/
void setIndent(MBool allowIndentation);
/**
* Sets the output method. Valid output method options are,
* "xml", "html", or "text".
* @param method the value to set the XML output method to. If
* the given String is not a valid method, the method will be
* set to "xml".
**/
void setMethod(const String& method);
/**
* Sets the xml output version that should be used when serializing
* XML documents.
* @param version the value to set the XML output version to.
**/
void setVersion(const String& version);
private:
//-- The xml character encoding that should be used when serializing
//-- xml documents
String encoding;
MBool explicitIndent;
MBool indent;
//-- The XSL output method, which can be "xml", "html", or "text"
String method;
MBool explicitMethod;
//-- The public Id for creating a DOCTYPE
String publicId;
//-- The System Id for creating a DOCTYPE
String systemId;
//-- The xml version number that should be used when serializing
//-- xml documents
String version;
};
#endif

Просмотреть файл

@ -21,14 +21,14 @@
* Keith Visco, kvisco@ziplink.net
* -- original author.
*
* $Id: ProcessorState.cpp,v 1.2 1999-11-15 07:13:07 nisheeth%netscape.com Exp $
* $Id: ProcessorState.cpp,v 1.3 1999-11-18 04:39:57 kvisco%ziplink.net Exp $
*/
/**
* Implementation of ProcessorState
* This code was ported from XSL:P
* @author <a href="kvisco@ziplink.net">Keith Visco</a>
* @version $Revision: 1.2 $ $Date: 1999-11-15 07:13:07 $
* @version $Revision: 1.3 $ $Date: 1999-11-18 04:39:57 $
**/
#include "ProcessorState.h"
@ -373,10 +373,26 @@ Element* ProcessorState::getNamedTemplate(String& name) {
} //-- getNamedTemplate
/**
* Returns the NodeStack which keeps track of where we are in the
* result tree
* @return the NodeStack which keeps track of where we are in the
* result tree
**/
NodeStack* ProcessorState::getNodeStack() {
return nodeStack;
} //-- getNodeStack
/**
* Returns the OutputFormat which contains information on how
* to serialize the output. I will be removing this soon, when
* change to an event based printer, so that I can serialize
* as I go
**/
OutputFormat* ProcessorState::getOutputFormat() {
return &format;
} //-- getOutputFormat
PatternExpr* ProcessorState::getPatternExpr(const String& pattern) {
PatternExpr* pExpr = (PatternExpr*)patternExprHash.get(pattern);
if ( !pExpr ) {
@ -521,6 +537,12 @@ MBool ProcessorState::isStripSpaceAllowed(Node* node) {
String name = node->getNodeName();
if (wsPreserve.contains(name)) return MB_FALSE;
if (wsStrip.contains(name)) return MB_TRUE;
String method;
if (format.getMethod(method).isEqual("html")) {
String ucName = name;
ucName.toUpperCase();
if (ucName.isEqual("SCRIPT")) return MB_FALSE;
}
break;
}
case Node::TEXT_NODE:
@ -651,6 +673,20 @@ void ProcessorState::initialize() {
defaultSpace = STRIP;
}
}
else if ( attName.isEqual(RESULT_NS_ATTR) ) {
if (attValue.length() > 0) {
if ( attValue.indexOf(HTML_NS) == 0 ) {
format.setMethod("html");
}
else format.setMethod(attValue);
}
}
else if ( attName.isEqual(INDENT_RESULT_ATTR) ) {
if ( attValue.length() > 0 ) {
format.setIndent(attValue.isEqual(YES_VALUE));
}
}
} //-- end for each att
} //-- end if atts are not null
} //-- end if document element exists

Просмотреть файл

@ -21,13 +21,13 @@
* Keith Visco, kvisco@ziplink.net
* -- original author.
*
* $Id: ProcessorState.h,v 1.2 1999-11-15 07:13:08 nisheeth%netscape.com Exp $
* $Id: ProcessorState.h,v 1.3 1999-11-18 04:39:58 kvisco%ziplink.net Exp $
*/
#ifndef MITREXSL_PROCESSORSTATE_H
#define MITREXSL_PROCESSORSTATE_H
#ifndef TRANSFRMX_PROCESSORSTATE_H
#define TRANSFRMX_PROCESSORSTATE_H
#include "dom.h"
#include "XMLUtils.h"
@ -43,11 +43,12 @@
#include "StringList.h"
#include "Tokenizer.h"
#include "VariableBinding.h"
#include "OutputFormat.h"
/**
* Class used for keeping the current state of the XSL Processor
* @author <a href="mailto:kvisco@ziplink.net">Keith Visco</a>
* @version $Revision: 1.2 $ $Date: 1999-11-15 07:13:08 $
* @version $Revision: 1.3 $ $Date: 1999-11-18 04:39:58 $
**/
class ProcessorState : public ContextState
{
@ -135,11 +136,27 @@ public:
**/
Element* getNamedTemplate(String& name);
NodeStack* getNodeStack();
Stack* getVariableSetStack();
/**
* Returns the NodeStack which keeps track of where we are in the
* result tree
* @return the NodeStack which keeps track of where we are in the
* result tree
**/
NodeStack* getNodeStack();
Expr* getExpr(const String& pattern);
PatternExpr* getPatternExpr(const String& pattern);
/**
* Returns the OutputFormat which contains information on how
* to serialize the output. I will be removing this soon, when
* change to an event based printer, so that I can serialize
* as I go
**/
OutputFormat* getOutputFormat();
Stack* getVariableSetStack();
Expr* getExpr(const String& pattern);
PatternExpr* getPatternExpr(const String& pattern);
/**
* Returns a pointer to the result document
@ -201,8 +218,8 @@ public:
/**
* Returns the value of a given variable binding within the current scope
* @param the name to which the desired variable value has been bound
* @return the ExprResult which has been bound to the variable with the given
* name
* @return the ExprResult which has been bound to the variable with
* the given name
**/
virtual ExprResult* getVariable(String& name);
@ -258,6 +275,12 @@ private:
**/
NodeStack* nodeStack;
/**
* The output format used when serializing the result
**/
OutputFormat format;
/**
* The set of whitespace preserving elements
**/

Просмотреть файл

@ -21,7 +21,7 @@
* Keith Visco, kvisco@ziplink.net
* -- original author.
*
* $Id: XSLProcessor.cpp,v 1.3 1999-11-15 07:48:36 nisheeth%netscape.com Exp $
* $Id: XSLProcessor.cpp,v 1.4 1999-11-18 04:39:58 kvisco%ziplink.net Exp $
*/
#include "XSLProcessor.h"
@ -34,7 +34,7 @@
/**
* XSLProcessor is a class for Processing XSL styelsheets
* @author <a href="mailto:kvisco@ziplink.net">Keith Visco</a>
* @version $Revision: 1.3 $ $Date: 1999-11-15 07:48:36 $
* @version $Revision: 1.4 $ $Date: 1999-11-18 04:39:58 $
**/
/**
@ -75,6 +75,7 @@ XSLProcessor::XSLProcessor() {
xslTypes.put(MESSAGE, new XSLType(XSLType::MESSAGE));
xslTypes.put(NUMBER, new XSLType(XSLType::NUMBER));
xslTypes.put(OTHERWISE, new XSLType(XSLType::OTHERWISE));
xslTypes.put(OUTPUT, new XSLType(XSLType::OUTPUT));
xslTypes.put(PARAM, new XSLType(XSLType::PARAM));
xslTypes.put(PI, new XSLType(XSLType::PI));
xslTypes.put(PRESERVE_SPACE, new XSLType(XSLType::PRESERVE_SPACE));
@ -134,36 +135,43 @@ void XSLProcessor::addErrorObserver(ErrorObserver& errorObserver) {
} //-- addErrorObserver
#ifndef MOZILLA
XMLPrinter* XSLProcessor::createPrinter(Document& xslDocument, ostream& out) {
void XSLProcessor::print
(Document& document, OutputFormat* format, ostream& out)
{
//-- check result-ns of stylesheet element
Element* stylesheet = xslDocument.getDocumentElement();
XMLPrinter* xmlPrinter = 0;
ostream* target = 0;
if ( !out ) target = &cout;
else target = &out;
if ( stylesheet ) {
String result_ns = stylesheet->getAttribute(RESULT_NS_ATTR);
Attr* indentResult = stylesheet->getAttributeNode(INDENT_RESULT_ATTR);
//-- create appropriate printer
if ( result_ns.indexOf(HTML_NS) == 0) {
xmlPrinter = new HTMLPrinter(*target);
}
MBool indent = MB_FALSE;
if (format->isMethodExplicit()) {
if (format->isHTMLOutput()) xmlPrinter = new HTMLPrinter(*target);
else xmlPrinter = new XMLPrinter(*target);
//-- set use formatting
if ( indentResult ) {
MBool useFormat = (MBool) YES_VALUE.isEqual(indentResult->getValue());
xmlPrinter->setUseFormat(useFormat);
}
indent = format->getIndent();
}
else xmlPrinter = new XMLPrinter(*target);
return xmlPrinter;
} //-- createPrinter
else {
//-- try to determine output method
Element* element = document.getDocumentElement();
String name;
if (element) name = element->getNodeName();
name.toUpperCase();
if (name.isEqual("HTML")) {
xmlPrinter = new HTMLPrinter(*target);
if (format->isIndentExplicit()) indent = format->getIndent();
else indent = MB_TRUE;
}
else {
xmlPrinter = new XMLPrinter(*target);
indent = format->getIndent();
}
}
xmlPrinter->setUseFormat(indent);
xmlPrinter->print(&document);
delete xmlPrinter;
} //-- print
#endif
String& XSLProcessor::getAppName() {
@ -207,8 +215,6 @@ void XSLProcessor::getHrefFromStylesheetPI(Document& xmlDocument, String& href)
} //-- getHrefFromStylesheetPI
/**
* Parses the contents of data, and returns the type and href psuedo attributes
**/
@ -354,8 +360,7 @@ Document* XSLProcessor::process(istream& xmlInput, String& documentBase) {
delete xslDoc;
return result;
} //-- process
#endif // #ifndef MOZILLA
#endif
/**
* Processes the Top level elements for an XSL stylesheet
@ -364,11 +369,16 @@ void XSLProcessor::processTopLevel
(Document* xslDocument, ProcessorState* ps)
{
if (!xslDocument) return;
//-------------------------------------------------------/
//- index templates and process top level xsl elements -/
//-------------------------------------------------------/
Element* stylesheet = xslDocument->getDocumentElement();
if (!stylesheet) return;
NodeList* nl = stylesheet->getChildNodes();
for (int i = 0; i < nl->getLength(); i++) {
Node* node = nl->item(i);
@ -443,6 +453,35 @@ void XSLProcessor::processTopLevel
break;
}
case XSLType::OUTPUT :
{
OutputFormat* format = ps->getOutputFormat();
String attValue = element->getAttribute(METHOD_ATTR);
if (attValue.length() > 0) format->setMethod(attValue);
attValue = element->getAttribute(VERSION_ATTR);
if (attValue.length() > 0) format->setVersion(attValue);
attValue = element->getAttribute(ENCODING_ATTR);
if (attValue.length() > 0) format->setEncoding(attValue);
attValue = element->getAttribute(INDENT_ATTR);
if (attValue.length() > 0) {
MBool allowIndent = attValue.isEqual(YES_VALUE);
format->setIndent(allowIndent);
}
attValue = element->getAttribute(DOCTYPE_PUBLIC_ATTR);
if (attValue.length() > 0)
format->setDoctypePublic(attValue);
attValue = element->getAttribute(DOCTYPE_SYSTEM_ATTR);
if (attValue.length() > 0)
format->setDoctypeSystem(attValue);
break;
}
case XSLType::TEMPLATE :
ps->addTemplate(element);
break;
@ -526,8 +565,7 @@ Document* XSLProcessor::process
return result;
} //-- process
#ifndef MOZILLA
#ifndef MOZILLA
/**
* Processes the given XML Document using the given XSL document
* and prints the results to the given ostream argument
@ -538,11 +576,35 @@ void XSLProcessor::process
ostream& out,
String& documentBase )
{
Document* resultDoc = process(xmlDocument, xslDocument, documentBase);
XMLPrinter* xmlPrinter = createPrinter(xslDocument, out);
xmlPrinter->print(resultDoc);
delete xmlPrinter;
delete resultDoc;
Document* result = new Document();
//-- create a new ProcessorState
ProcessorState ps(xslDocument, *result);
ps.setDocumentBase(documentBase);
//-- add error observers
ListIterator* iter = errorObservers.iterator();
while ( iter->hasNext()) {
ps.addErrorObserver(*((ErrorObserver*)iter->next()));
}
delete iter;
//-------------------------------------------------------/
//- index templates and process top level xsl elements -/
//-------------------------------------------------------/
processTopLevel(&xslDocument, &ps);
//----------------------------------------/
//- Process root of XML source document -/
//--------------------------------------/
process(&xmlDocument, &xmlDocument, &ps);
print(*result, ps.getOutputFormat(), out);
delete result;
} //-- process
@ -583,13 +645,9 @@ void XSLProcessor::process
delete xmlDoc;
return;
}
Document* result = process(*xmlDoc, *xslDoc, documentBase);
XMLPrinter* xmlPrinter = createPrinter(*xslDoc, out);
xmlPrinter->print(result);
delete xmlPrinter;
process(*xmlDoc, *xslDoc, out, documentBase);
delete xmlDoc;
delete xslDoc;
delete result;
} //-- process
/**
@ -620,15 +678,12 @@ void XSLProcessor::process
delete xmlDoc;
return;
}
Document* result = process(*xmlDoc, *xslDoc, documentBase);
XMLPrinter* xmlPrinter = createPrinter(*xslDoc, out);
xmlPrinter->print(result);
delete xmlPrinter;
process(*xmlDoc, *xslDoc, out, documentBase);
delete xmlDoc;
delete xslDoc;
delete result;
} //-- process
#endif // #ifndef MOZILLA
#endif // ifndef MOZILLA
//-------------------/
//- Private Methods -/

Просмотреть файл

@ -21,12 +21,12 @@
* Keith Visco, kvisco@ziplink.net
* -- original author.
*
* $Id: XSLProcessor.h,v 1.3 1999-11-15 07:48:36 nisheeth%netscape.com Exp $
* $Id: XSLProcessor.h,v 1.4 1999-11-18 04:39:59 kvisco%ziplink.net Exp $
*/
#ifndef MITREXSL_XSLPROCESSOR_H
#define MITREXSL_XSLPROCESSOR_H
#ifndef TRANSFRMX_XSLPROCESSOR_H
#define TRANSFRMX_XSLPROCESSOR_H
#ifndef __BORLANDC__
#ifndef MOZILLA
@ -35,6 +35,7 @@
#endif
#endif
#ifdef MOZILLA
#include "nsIDocumentTransformer.h"
#else
@ -59,6 +60,7 @@
#include "VariableBinding.h"
#include "Numbering.h"
#ifdef MOZILLA
/* bacd8ad0-552f-11d3-a9f7-000064657374 */
#define MITRE_XSL_PROCESSOR_CID \
@ -66,10 +68,11 @@
#endif
/**
* A class for Processing XSL Stylesheets
* @author <a href="mailto:kvisco@ziplink.net">Keith Visco</a>
* @version $Revision: 1.3 $ $Date: 1999-11-15 07:48:36 $
* @version $Revision: 1.4 $ $Date: 1999-11-18 04:39:59 $
**/
class XSLProcessor
#ifdef MOZILLA
@ -114,11 +117,7 @@ public:
/**
* Default destructor for XSLProcessor
**/
#ifdef MOZILLA
virtual ~XSLProcessor();
#else
~XSLProcessor();
#endif
/**
* Registers the given ErrorObserver with this XSLProcessor
@ -158,6 +157,7 @@ public:
* @return the result tree.
**/
Document* process(Document& xmlDocument, String& documentBase);
#endif
/**
@ -271,9 +271,19 @@ private:
ProcessorState* ps);
#ifndef MOZILLA
XMLPrinter* createPrinter(Document& xslDocument, ostream& out);
/**
* Prints the given XML document to the given ostream and uses
* the properties specified in the OutputFormat.
* This method is used to print the result tree
* @param document the XML document to print
* @param format the OutputFormat specifying formatting info
* @param ostream the Stream to print to
**/
void print(Document& document, OutputFormat* format, ostream& out);
#endif
/**
* Processes the xsl:with-param elements of the given xsl action
**/
@ -380,6 +390,7 @@ public:
LITERAL,
NUMBER,
OTHERWISE,
OUTPUT,
PARAM,
PI,
PRESERVE_SPACE,
@ -401,3 +412,5 @@ public:
};
#endif

Просмотреть файл

@ -3,36 +3,36 @@
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/MPL/
*
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
*
* The Original Code is TransforMiiX XSLT processor.
*
*
* The Initial Developer of the Original Code is The MITRE Corporation.
* Portions created by MITRE are Copyright (C) 1999 The MITRE Corporation.
*
* Portions created by Keith Visco as a Non MITRE employee,
* (C) 1999 Keith Visco. All Rights Reserved.
*
* Contributor(s):
*
* Contributor(s):
* Keith Visco, kvisco@ziplink.net
* -- original author.
* Larry Fitzpatick, OpenText, lef@opentext.com
* -- 19990806
* -- 19990806
* - changed constant short declarations in many of the classes
* with enumerations, commented with //--LF
*
* $Id: Expr.h,v 1.2 1999-11-15 07:13:10 nisheeth%netscape.com Exp $
* $Id: Expr.h,v 1.3 1999-11-18 04:40:01 kvisco%ziplink.net Exp $
*/
/**
* XSL expression class definitions.
* Much of this code was ported from XSL:P. <BR />
* @author <A HREF="mailto:kvisco@ziplink.net">Keith Visco</A>
* @version $Revision: 1.2 $ $Date: 1999-11-15 07:13:10 $
* @version $Revision: 1.3 $ $Date: 1999-11-18 04:40:01 $
**/
#ifndef MITREXSL_EXPR_H
@ -72,7 +72,7 @@ public:
* handles finding the parent of a node, since in DOM some
* nodes such as Attribute Nodes do not have parents
* @param node the Node to search for the parent of
* @return the parent of the given node, or null
* @return the parent of the given node, or null
**/
virtual Node* findParent(Node* node) = 0;
@ -1228,6 +1228,8 @@ private:
short op;
Expr* leftExpr;
Expr* rightExpr;
MBool compareResults(ExprResult* left, ExprResult* right);
}; //-- RelationalExpr
/**

Просмотреть файл

@ -3,35 +3,35 @@
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/MPL/
*
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
*
* The Original Code is TransforMiiX XSLT processor.
*
*
* The Initial Developer of the Original Code is The MITRE Corporation.
* Portions created by MITRE are Copyright (C) 1999 The MITRE Corporation.
*
* Portions created by Keith Visco as a Non MITRE employee,
* (C) 1999 Keith Visco. All Rights Reserved.
*
* Contributor(s):
*
* Contributor(s):
* Keith Visco, kvisco@ziplink.net
* -- original author.
* -- fixed bug with '<=' and '>=' reported by Bob Miller
*
*
* Bob Miller, Oblix Inc., kbob@oblix.com
* -- fixed bug with single quotes inside double quotes
*
* $Id: ExprLexer.cpp,v 1.2 1999-11-15 07:13:11 nisheeth%netscape.com Exp $
*
* $Id: ExprLexer.cpp,v 1.3 1999-11-18 04:40:01 kvisco%ziplink.net Exp $
*/
/**
* Lexical analyzer for XPath expressions
* @author <a href="mailto:kvisco@ziplink.net">Keith Visco</a>
* @version $Revision: 1.2 $ $Date: 1999-11-15 07:13:11 $
* @version $Revision: 1.3 $ $Date: 1999-11-18 04:40:01 $
**/
#include <iostream.h>
@ -589,17 +589,22 @@ void ExprLexer::parse(const String& pattern) {
else matchDelimiter(ch);
break;
case BANG : //-- used as previous...see EQUAL
matchToken(tokenBuffer,ch);
addToken(new Token(ch, Token::ERROR));
break;
case EQUAL:
switch ( prevCh ) {
case BANG:
prevToken->type = Token::NOT_EQUAL_OP;
prevToken->value.append("=");
break;
case L_ANGLE:
prevToken->type = Token::LESS_OR_EQUAL_OP;
prevToken->value.append("=");
break;
case R_ANGLE:
prevToken->type = Token::GREATER_OR_EQUAL_OP;
prevToken->value.append("=");
break;
default:
matchToken(tokenBuffer, ch);

Просмотреть файл

@ -3,33 +3,33 @@
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/MPL/
*
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
*
* The Original Code is TransforMiiX XSLT processor.
*
*
* The Initial Developer of the Original Code is The MITRE Corporation.
* Portions created by MITRE are Copyright (C) 1999 The MITRE Corporation.
*
* Portions created by Keith Visco as a Non MITRE employee,
* (C) 1999 Keith Visco. All Rights Reserved.
*
* Contributor(s):
*
* Contributor(s):
* Keith Visco, kvisco@ziplink.net
* -- original author.
*
* $Id: ExprParser.cpp,v 1.2 1999-11-15 07:13:11 nisheeth%netscape.com Exp $
*
* $Id: ExprParser.cpp,v 1.3 1999-11-18 04:40:02 kvisco%ziplink.net Exp $
*/
/**
* ExprParser
* This class is used to parse XSL Expressions
* @author <A HREF="mailto:kvisco@ziplink.net">Keith Visco</A>
* @author <A HREF="mailto:kvisco@ziplink.net">Keith Visco</A>
* @see ExprLexer
* @version $Revision: 1.2 $ $Date: 1999-11-15 07:13:11 $
* @version $Revision: 1.3 $ $Date: 1999-11-18 04:40:02 $
**/
#include "ExprParser.h"
@ -251,7 +251,7 @@ Expr* ExprParser::createExpr(ExprLexer& lexer) {
PathExpr::RELATIVE_OP);
expr = pathExpr;
}
done = MB_TRUE;
//done = MB_TRUE;
break;
case Token::UNION_OP :
{
@ -365,6 +365,7 @@ FilterExpr* ExprParser::createFilterExpr(ExprLexer& lexer) {
}
//-- handle predicates
parsePredicates(filterExpr, lexer);
return filterExpr;
@ -639,6 +640,10 @@ PathExpr* ExprParser::createPathExpr(ExprLexer& lexer) {
while ( lexer.hasMoreTokens() ) {
Token* tok = lexer.nextToken();
if ( lexer.isOperatorToken(tok) ) {
lexer.pushBack();
return pathExpr;
}
switch ( tok->type ) {
case Token::R_PAREN:
case Token::R_BRACKET:

Просмотреть файл

@ -3,25 +3,25 @@
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/MPL/
*
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
*
* The Original Code is TransforMiiX XSLT processor.
*
*
* The Initial Developer of the Original Code is The MITRE Corporation.
* Portions created by MITRE are Copyright (C) 1999 The MITRE Corporation.
*
* Portions created by Keith Visco as a Non MITRE employee,
* (C) 1999 Keith Visco. All Rights Reserved.
*
* Contributor(s):
*
* Contributor(s):
* Keith Visco, kvisco@ziplink.net
* -- original author.
*
* $Id: RelationalExpr.cpp,v 1.2 1999-11-15 07:13:13 nisheeth%netscape.com Exp $
*
* $Id: RelationalExpr.cpp,v 1.3 1999-11-18 04:40:02 kvisco%ziplink.net Exp $
*/
#include "Expr.h"
@ -47,6 +47,102 @@ RelationalExpr::~RelationalExpr() {
delete rightExpr;
} //-- ~RelationalExpr
/**
* Compares the two ExprResults based on XPath 1.0 Recommendation (section 3.4)
**/
MBool RelationalExpr::compareResults(ExprResult* left, ExprResult* right) {
short ltype = left->getResultType();
short rtype = right->getResultType();
MBool result = MB_FALSE;
//-- handle case for just Left NodeSet or Both NodeSets
if (ltype == ExprResult::NODESET) {
NodeSet* nodeSet = (NodeSet*)left;
for ( int i = 0; i < nodeSet->size(); i++) {
String str;
Node* node = nodeSet->get(i);
XMLDOMUtils::getNodeValue(node, &str);
StringResult strResult(str);
result = compareResults(&strResult, right);
if ( result ) break;
}
}
//-- handle case for Just Right NodeSet
else if ( rtype == ExprResult::NODESET) {
NodeSet* nodeSet = (NodeSet*)right;
for ( int i = 0; i < nodeSet->size(); i++) {
String str;
Node* node = nodeSet->get(i);
XMLDOMUtils::getNodeValue(node, &str);
StringResult strResult(str);
result = compareResults(left, &strResult);
if ( result ) break;
}
}
//-- neither NodeSet
else {
if ( op == NOT_EQUAL) {
if ((ltype == ExprResult::BOOLEAN)
|| (rtype == ExprResult::BOOLEAN)) {
result = (left->booleanValue() != right->booleanValue());
}
else if ((ltype == ExprResult::NUMBER) ||
(rtype == ExprResult::NUMBER)) {
result = (left->numberValue() != right->numberValue());
}
else {
String lStr;
left->stringValue(lStr);
String rStr;
right->stringValue(rStr);
result = !lStr.isEqual(rStr);
}
}
else if ( op == EQUAL) {
if ((ltype == ExprResult::BOOLEAN)
|| (rtype == ExprResult::BOOLEAN)) {
result = (left->booleanValue() == right->booleanValue());
}
else if ((ltype == ExprResult::NUMBER) ||
(rtype == ExprResult::NUMBER)) {
result = (left->numberValue() == right->numberValue());
}
else {
String lStr;
left->stringValue(lStr);
String rStr;
right->stringValue(rStr);
result = lStr.isEqual(rStr);
}
}
else {
double leftDbl = left->numberValue();
double rightDbl = right->numberValue();
switch( op ) {
case LESS_THAN:
result = (MBool) (leftDbl < rightDbl);
break;
case LESS_OR_EQUAL:
result = (MBool) (leftDbl <= rightDbl);
break;
case GREATER_THAN :
result = (MBool) (leftDbl > rightDbl);
break;
case GREATER_OR_EQUAL:
result = (MBool) (leftDbl >= rightDbl);
break;
}
}
}
return result;
} //-- compareResult
/**
* Evaluates this Expr based on the given context node and processor state
* @param context the context node for evaluation of this Expr
@ -56,47 +152,19 @@ RelationalExpr::~RelationalExpr() {
**/
ExprResult* RelationalExpr::evaluate(Node* context, ContextState* cs) {
//-- get result of left expression
ExprResult* lResult = 0;
if ( leftExpr ) lResult = leftExpr->evaluate(context, cs);
else return new BooleanResult();
double rightDbl = Double::NaN;
ExprResult* exprRes = 0;
if ( rightExpr ) {
exprRes = rightExpr->evaluate(context, cs);
if ( exprRes ) rightDbl = exprRes->numberValue();
delete exprRes;
//-- get result of right expr
ExprResult* rResult = 0;
if ( rightExpr ) rResult = rightExpr->evaluate(context, cs);
else {
delete lResult;
return new BooleanResult();
}
double leftDbl = Double::NaN;
if ( leftExpr ) {
exprRes = leftExpr->evaluate(context, cs);
if ( exprRes ) leftDbl = exprRes->numberValue();
delete exprRes;
}
MBool result = MB_FALSE;
switch ( op ) {
case NOT_EQUAL:
result = (MBool) (leftDbl != rightDbl);
break;
case LESS_THAN:
result = (MBool) (leftDbl < rightDbl);
break;
case LESS_OR_EQUAL:
result = (MBool) (leftDbl <= rightDbl);
break;
case GREATER_THAN :
result = (MBool) (leftDbl > rightDbl);
break;
case GREATER_OR_EQUAL:
result = (MBool) (leftDbl >= rightDbl);
break;
default:
result = (MBool) (leftDbl == rightDbl);
break;
}
return new BooleanResult(result);
return new BooleanResult(compareResults(lResult, rResult));
} //-- evaluate
/**