You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xalan.apache.org by dl...@apache.org on 2002/06/04 21:11:05 UTC
cvs commit: xml-xalan/java/src/org/apache/xalan/processor ProcessorFuncResult.java ProcessorFunction.java ProcessorResultDocument.java ProcessorOutputElem.java XSLTSchema.java
dleslie 2002/06/04 12:11:04
Modified: java/src/org/apache/xalan/processor ProcessorOutputElem.java
XSLTSchema.java
Added: java/src/org/apache/xalan/processor ProcessorFuncResult.java
ProcessorFunction.java ProcessorResultDocument.java
Log:
XSLT 2.0: stylesheet function, result-document, and
principal-result-document.
Revision Changes Path
1.13 +18 -4 xml-xalan/java/src/org/apache/xalan/processor/ProcessorOutputElem.java
Index: ProcessorOutputElem.java
===================================================================
RCS file: /home/cvs/xml-xalan/java/src/org/apache/xalan/processor/ProcessorOutputElem.java,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -r1.12 -r1.13
--- ProcessorOutputElem.java 2 Jan 2001 03:36:42 -0000 1.12
+++ ProcessorOutputElem.java 4 Jun 2002 19:11:04 -0000 1.13
@@ -72,6 +72,7 @@
import org.xml.sax.Attributes;
+
/**
* TransformerFactory for xsl:output markup.
* @see <a href="http://www.w3.org/TR/xslt#dtd">XSLT DTD</a>
@@ -79,7 +80,7 @@
*/
class ProcessorOutputElem extends XSLTElementProcessor
{
-
+
/** The output properties, set temporarily while the properties are
* being set from the attributes, and then nulled after that operation
* is completed. */
@@ -90,7 +91,7 @@
* @see javax.xml.transform.OutputKeys#CDATA_SECTION_ELEMENTS
* @param newValue non-null reference to processed attribute value.
*/
- public void setCdataSectionElements(java.util.Vector newValue)
+ public void setCdataSectionElements(java.util.Vector newValue, QName qname)
{
m_outputProperties.setQNameProperties(OutputKeys.CDATA_SECTION_ELEMENTS, newValue);
}
@@ -204,6 +205,18 @@
QName key = new QName(attrUri, attrLocalName);
m_outputProperties.setProperty(key, attrValue);
}
+
+ //XSLT 2.0
+
+ public void setName(QName v)
+ {
+ m_outputProperties.setQNameProperty("name", v);
+ }
+
+ public QName getName()
+ {
+ return m_outputProperties.getQNameProperty("name");
+ }
/**
* Receive notification of the start of an xsl:output element.
@@ -234,7 +247,7 @@
m_outputProperties.setLocaterInfo(handler.getLocator());
m_outputProperties.setUid(handler.nextUid());
setPropertiesFromAttributes(handler, rawName, attributes, this);
-
+
// Access this only from the Hashtable level... we don't want to
// get default properties.
String entitiesFileName =
@@ -254,7 +267,8 @@
}
}
- handler.getStylesheet().setOutput(m_outputProperties);
+ // for 2.0, can have multiple output properties, identified by name.
+ handler.getStylesheet().setOutput(m_outputProperties);
ElemTemplateElement parent = handler.getElemTemplateElement();
parent.appendChild(m_outputProperties);
1.24 +262 -163 xml-xalan/java/src/org/apache/xalan/processor/XSLTSchema.java
Index: XSLTSchema.java
===================================================================
RCS file: /home/cvs/xml-xalan/java/src/org/apache/xalan/processor/XSLTSchema.java,v
retrieving revision 1.23
retrieving revision 1.24
diff -u -r1.23 -r1.24
--- XSLTSchema.java 26 Sep 2001 15:13:15 -0000 1.23
+++ XSLTSchema.java 4 Jun 2002 19:11:04 -0000 1.24
@@ -86,6 +86,9 @@
XSLTAttributeDef hrefAttr = new XSLTAttributeDef(null, "href",
XSLTAttributeDef.T_URL, true);
+ XSLTAttributeDef hrefAttrOpt = new XSLTAttributeDef(null, "href",
+ XSLTAttributeDef.T_URL, false);
+
XSLTAttributeDef elementsAttr = new XSLTAttributeDef(null, "elements",
XSLTAttributeDef.T_SIMPLEPATTERNLIST,
true);
@@ -247,6 +250,20 @@
XSLTAttributeDef xslVersionAttr =
new XSLTAttributeDef(Constants.S_XSLNAMESPACEURL, "version",
XSLTAttributeDef.T_NMTOKEN, false);
+ //dml for result-document
+ XSLTAttributeDef resultDocFormatAttr =
+ new XSLTAttributeDef(null, "format",
+ XSLTAttributeDef.T_QNAME, false);
+ // dml for output
+ XSLTAttributeDef includeContentTypeAttr = new XSLTAttributeDef(null,
+ "include-content-type",
+ XSLTAttributeDef.T_YESNO,
+ false);
+ XSLTAttributeDef escapeUriAttributesAttr = new XSLTAttributeDef(null,
+ "excape-uri-asttributes",
+ XSLTAttributeDef.T_YESNO,
+ false);
+
XSLTElementDef charData = new XSLTElementDef(this, null, "text()",
null /*alias */, null /* elements */, null, /* attributes */
new ProcessorCharacters(),
@@ -267,9 +284,12 @@
XSLTAttributeDef xslResultAttr =
new XSLTAttributeDef(Constants.S_XSLNAMESPACEURL, "*",
XSLTAttributeDef.T_CDATA, false);
- XSLTElementDef[] templateElements = new XSLTElementDef[21];
- XSLTElementDef[] templateElementsAndParams = new XSLTElementDef[22];
- XSLTElementDef[] templateElementsAndSort = new XSLTElementDef[22];
+ XSLTElementDef[] templateElements = new XSLTElementDef[24];
+ XSLTElementDef[] templateElementsAndParams = new XSLTElementDef[25];
+ XSLTElementDef[] templateElementsAndSort = new XSLTElementDef[25];
+ //exslt
+ XSLTElementDef[] exsltFunctionElements = new XSLTElementDef[25];// although should exclude some template elements.
+
XSLTElementDef[] charTemplateElements = new XSLTElementDef[15];
XSLTElementDef resultElement = new XSLTElementDef(this, null, "*",
null /*alias */,
@@ -293,8 +313,8 @@
xslVersionAttr,
xslResultAttr,
resultAttr },
- new ProcessorUnknown(),
- ElemUnknown.class /* class object */, 20, true);
+ new ProcessorUnknown(),
+ ElemUnknown.class /* class object */, 20, true);
XSLTElementDef xslValueOf = new XSLTElementDef(this,
Constants.S_XSLNAMESPACEURL, "value-of",
null /*alias */, null /* elements */,
@@ -485,8 +505,67 @@
new XSLTAttributeDef[]{ spaceAttr },
new ProcessorTemplateElem(),
ElemFallback.class /* class object */, 20, true);
+ //exslt
+ XSLTElementDef exsltFunction =
+ new XSLTElementDef(this,
+ Constants.S_EXSLT_FUNCTIONS_URL,
+ "function",
+ null /*alias */,
+ exsltFunctionElements /* elements */,
+ new XSLTAttributeDef[]{ nameAttrRequired },
+ new ProcessorExsltFunction(),
+ ElemExsltFunction.class /* class object */);
+ XSLTElementDef exsltResult =
+ new XSLTElementDef(this,
+ Constants.S_EXSLT_FUNCTIONS_URL,
+ "result",
+ null /*alias */,
+ templateElements /* elements */,
+ new XSLTAttributeDef[]{ selectAttrOpt },
+ new ProcessorExsltFuncResult(),
+ ElemExsltFuncResult.class /* class object */);
+
+ //XSLT 2.0
+ XSLTElementDef xslResult = new XSLTElementDef(this,
+ Constants.S_XSLNAMESPACEURL,
+ "result",
+ null /*alias */,
+ templateElements /* elements */,
+ new XSLTAttributeDef[]{ selectAttrOpt },
+ new ProcessorFuncResult(),
+ ElemFuncResult.class /* class object */);
+ XSLTElementDef[] xslFunctionElements = new XSLTElementDef[]
+ {xslParam, xslVariable,
+ xslMessage, xslComment,
+ xslResult};
+ XSLTElementDef xslFunction = new XSLTElementDef(this,
+ Constants.S_XSLNAMESPACEURL,
+ "function",
+ null,
+ xslFunctionElements,
+ new XSLTAttributeDef[]{ nameAttrRequired },
+ new ProcessorFunction(),
+ ElemFunction.class /* class object */);
+
+ XSLTElementDef xslPrincipalResultDocument =
+ new XSLTElementDef(this,
+ Constants.S_XSLNAMESPACEURL, "principal-result-document",
+ null /*alias */,
+ templateElements,
+ new XSLTAttributeDef[]{resultDocFormatAttr, hrefAttrOpt},
+ new ProcessorResultDocument(),
+ ElemPrincipalResultDocument.class);
+
+ XSLTElementDef xslResultDocument =
+ new XSLTElementDef(this,
+ Constants.S_XSLNAMESPACEURL, "result-document",
+ null /*alias */,
+ templateElements,
+ new XSLTAttributeDef[]{resultDocFormatAttr, hrefAttr},
+ new ProcessorResultDocument(),
+ ElemResultDocument.class);
+
int i = 0;
-
templateElements[i++] = charData; // #PCDATA
// char-instructions
@@ -512,22 +591,22 @@
templateElements[i++] = xslAttribute;
templateElements[i++] = resultElement;
templateElements[i++] = unknownElement;
+ templateElements[i++] = xslResult;
+ templateElements[i++] = exsltResult;
+ templateElements[i++] = xslResultDocument; // May NOT appear in xslFunction or exsltFunction.
int k;
for (k = 0; k < i; k++)
{
templateElementsAndParams[k] = templateElements[k];
- }
-
- templateElementsAndParams[k] = xslParam;
-
- for (k = 0; k < i; k++)
- {
templateElementsAndSort[k] = templateElements[k];
+ exsltFunctionElements[k] = templateElements[k];
}
-
+ templateElementsAndParams[k] = xslParam;
templateElementsAndSort[k] = xslSort;
+ exsltFunctionElements[k] = xslParam;
+
i = 0;
charTemplateElements[i++] = charData; // #PCDATA
@@ -561,156 +640,176 @@
new ProcessorInclude(),
null /* class object */,
20, true);
- XSLTElementDef[] topLevelElements = new XSLTElementDef[]{ includeDef,
- importDef,
- // resultElement,
- whiteSpaceOnly,
- unknownElement,
- new XSLTElementDef(
- this,
- Constants.S_XSLNAMESPACEURL,
- "strip-space",
- null /*alias */,
- null /* elements */,
- new XSLTAttributeDef[]{
- elementsAttr },
- new ProcessorStripSpace(),
- null /* class object */, 20, true),
- new XSLTElementDef(
- this,
- Constants.S_XSLNAMESPACEURL,
- "preserve-space",
- null /*alias */,
- null /* elements */,
- new XSLTAttributeDef[]{
- elementsAttr },
- new ProcessorPreserveSpace(),
- null /* class object */, 20, true),
- new XSLTElementDef(
- this,
- Constants.S_XSLNAMESPACEURL,
- "output",
- null /*alias */,
- null /* elements */,
- new XSLTAttributeDef[]{
- methodAttr,
- versionAttr,
- encodingAttr,
- omitXmlDeclarationAttr,
- standaloneAttr,
- doctypePublicAttr,
- doctypeSystemAttr,
- cdataSectionElementsAttr,
- indentAttr,
- mediaTypeAttr,
- XSLTAttributeDef.m_foreignAttr },
- new ProcessorOutputElem(), null /* class object */, 20, true),
- new XSLTElementDef(
- this,
- Constants.S_XSLNAMESPACEURL,
- "key",
- null /*alias */,
- null /* elements */, // EMPTY
- new XSLTAttributeDef[]{ nameAttrRequired,
- matchAttrRequired,
- useAttr },
- new ProcessorKey(), null /* class object */, 20, true),
- new XSLTElementDef(
- this,
- Constants.S_XSLNAMESPACEURL,
- "decimal-format",
- null /*alias */,
- null /* elements */, // EMPTY
- new XSLTAttributeDef[]{
- nameAttrOpt,
- decimalSeparatorAttr,
- groupingSeparatorAttr,
- infinityAttr,
- minusSignAttr,
- NaNAttr,
- percentAttr,
- perMilleAttr,
- zeroDigitAttr,
- digitAttr,
- patternSeparatorAttr },
- new ProcessorDecimalFormat(),
- null /* class object */, 20, true),
- new XSLTElementDef(
- this,
- Constants.S_XSLNAMESPACEURL,
- "attribute-set",
- null /*alias */,
- new XSLTElementDef[]{
- xslAttribute } /* elements */,
- new XSLTAttributeDef[]{
- nameAttrRequired,
- useAttributeSetsAttr }, new ProcessorAttributeSet(),
- null /* class object */, 20, true),
- new XSLTElementDef(
- this,
- Constants.S_XSLNAMESPACEURL,
- "variable",
- null /*alias */,
- templateElements /* elements */,
- new XSLTAttributeDef[]{
- nameAttrRequired,
- selectAttrOpt }, new ProcessorGlobalVariableDecl(),
- ElemVariable.class /* class object */, 20, true),
- new XSLTElementDef(
- this,
- Constants.S_XSLNAMESPACEURL,
- "param",
- null /*alias */,
- templateElements /* elements */,
- new XSLTAttributeDef[]{
- nameAttrRequired,
- selectAttrOpt }, new ProcessorGlobalParamDecl(),
- ElemParam.class /* class object */, 20, true),
- new XSLTElementDef(
- this,
- Constants.S_XSLNAMESPACEURL,
- "template",
- null /*alias */,
- templateElementsAndParams /* elements */,
- new XSLTAttributeDef[]{
- matchAttrOpt,
- nameAttrOpt,
- priorityAttr,
- modeAttr,
- spaceAttr }, new ProcessorTemplate(), ElemTemplate.class /* class object */, true, 20, true),
- new XSLTElementDef(
- this,
- Constants.S_XSLNAMESPACEURL,
- "namespace-alias",
- null /*alias */,
- null /* elements */, // EMPTY
- new XSLTAttributeDef[]{ stylesheetPrefixAttr,
- resultPrefixAttr },
- new ProcessorNamespaceAlias(), null /* class object */, 20, true),
- new XSLTElementDef(
- this,
- Constants.S_BUILTIN_EXTENSIONS_URL,
- "component",
- null /*alias */,
- new XSLTElementDef[]{
- new XSLTElementDef(
- this,
- Constants.S_BUILTIN_EXTENSIONS_URL,
- "script",
- null /*alias */,
- new XSLTElementDef[]{ charData } /* elements */,
- new XSLTAttributeDef[]{
- new XSLTAttributeDef(
- null,
- "lang",
- XSLTAttributeDef.T_NMTOKEN,
- true),
- new XSLTAttributeDef(null, "src", XSLTAttributeDef.T_URL, false) },
- new ProcessorLRE(),
- ElemExtensionScript.class /* class object */, 20, true) }, // EMPTY
- new XSLTAttributeDef[]{ new XSLTAttributeDef(null, "prefix", XSLTAttributeDef.T_NMTOKEN, true),
- new XSLTAttributeDef(null, "elements", XSLTAttributeDef.T_STRINGLIST, false),
- new XSLTAttributeDef(null, "functions", XSLTAttributeDef.T_STRINGLIST, false) }, new ProcessorLRE(), ElemExtensionDecl.class /* class object */) };
+
+ XSLTElementDef[] topLevelElements = new XSLTElementDef[]
+ {includeDef,
+ importDef,
+ // resultElement,
+ whiteSpaceOnly,
+ unknownElement,
+ new XSLTElementDef(
+ this,
+ Constants.S_XSLNAMESPACEURL,
+ "strip-space",
+ null /*alias */,
+ null /* elements */,
+ new XSLTAttributeDef[]{
+ elementsAttr },
+ new ProcessorStripSpace(),
+ null /* class object */, 20, true),
+ new XSLTElementDef(
+ this,
+ Constants.S_XSLNAMESPACEURL,
+ "preserve-space",
+ null /*alias */,
+ null /* elements */,
+ new XSLTAttributeDef[]{
+ elementsAttr },
+ new ProcessorPreserveSpace(),
+ null /* class object */, 20, true),
+ new XSLTElementDef(
+ this,
+ Constants.S_XSLNAMESPACEURL,
+ "output",
+ null /*alias */,
+ null /* elements */,
+ new XSLTAttributeDef[]{
+ nameAttrOpt /*2.0-dml */,
+ methodAttr,
+ versionAttr,
+ encodingAttr,
+ omitXmlDeclarationAttr,
+ standaloneAttr,
+ doctypePublicAttr,
+ doctypeSystemAttr,
+ cdataSectionElementsAttr,
+ indentAttr,
+ mediaTypeAttr,
+ includeContentTypeAttr,
+ escapeUriAttributesAttr,
+ XSLTAttributeDef.m_foreignAttr },
+ new ProcessorOutputElem(), null /* class object */, 20, true),
+ new XSLTElementDef(
+ this,
+ Constants.S_XSLNAMESPACEURL,
+ "key",
+ null /*alias */,
+ null /* elements */, // EMPTY
+ new XSLTAttributeDef[]{ nameAttrRequired,
+ matchAttrRequired,
+ useAttr },
+ new ProcessorKey(), null /* class object */, 20, true),
+ new XSLTElementDef(
+ this,
+ Constants.S_XSLNAMESPACEURL,
+ "decimal-format",
+ null /*alias */,
+ null /* elements */, // EMPTY
+ new XSLTAttributeDef[]{
+ nameAttrOpt,
+ decimalSeparatorAttr,
+ groupingSeparatorAttr,
+ infinityAttr,
+ minusSignAttr,
+ NaNAttr,
+ percentAttr,
+ perMilleAttr,
+ zeroDigitAttr,
+ digitAttr,
+ patternSeparatorAttr },
+ new ProcessorDecimalFormat(),
+ null /* class object */, 20, true),
+ new XSLTElementDef(
+ this,
+ Constants.S_XSLNAMESPACEURL,
+ "attribute-set",
+ null /*alias */,
+ new XSLTElementDef[]{
+ xslAttribute } /* elements */,
+ new XSLTAttributeDef[]{
+ nameAttrRequired,
+ useAttributeSetsAttr },
+ new ProcessorAttributeSet(),
+ null /* class object */, 20, true),
+ new XSLTElementDef(
+ this,
+ Constants.S_XSLNAMESPACEURL,
+ "variable",
+ null /*alias */,
+ templateElements /* elements */,
+ new XSLTAttributeDef[]{
+ nameAttrRequired,
+ selectAttrOpt },
+ new ProcessorGlobalVariableDecl(),
+ ElemVariable.class /* class object */, 20, true),
+ new XSLTElementDef(
+ this,
+ Constants.S_XSLNAMESPACEURL,
+ "param",
+ null /*alias */,
+ templateElements /* elements */,
+ new XSLTAttributeDef[]{
+ nameAttrRequired,
+ selectAttrOpt },
+ new ProcessorGlobalParamDecl(),
+ ElemParam.class /* class object */, 20, true),
+ new XSLTElementDef(
+ this,
+ Constants.S_XSLNAMESPACEURL,
+ "template",
+ null /*alias */,
+ templateElementsAndParams /* elements */,
+ new XSLTAttributeDef[]{
+ matchAttrOpt,
+ nameAttrOpt,
+ priorityAttr,
+ modeAttr,
+ spaceAttr },
+ new ProcessorTemplate(), ElemTemplate.class /* class object */, true, 20, true),
+ new XSLTElementDef(
+ this,
+ Constants.S_XSLNAMESPACEURL,
+ "namespace-alias",
+ null /*alias */,
+ null /* elements */, // EMPTY
+ new XSLTAttributeDef[]{
+ stylesheetPrefixAttr,
+ resultPrefixAttr },
+ new ProcessorNamespaceAlias(), null /* class object */, 20, true),
+ new XSLTElementDef(
+ this,
+ Constants.S_BUILTIN_EXTENSIONS_URL,
+ "component",
+ null /*alias */,
+ new XSLTElementDef[]{
+ new XSLTElementDef(
+ this,
+ Constants.S_BUILTIN_EXTENSIONS_URL,
+ "script",
+ null /*alias */,
+ new XSLTElementDef[]{
+ charData } /* elements */,
+ new XSLTAttributeDef[]{
+ new XSLTAttributeDef(
+ null,
+ "lang",
+ XSLTAttributeDef.T_NMTOKEN,
+ true),
+ new XSLTAttributeDef(
+ null, "src", XSLTAttributeDef.T_URL, false) },
+ new ProcessorLRE(),
+ ElemExtensionScript.class /* class object */, 20, true) }, // EMPTY
+ new XSLTAttributeDef[]{
+ new XSLTAttributeDef(
+ null, "prefix", XSLTAttributeDef.T_NMTOKEN, true),
+ new XSLTAttributeDef(
+ null, "elements", XSLTAttributeDef.T_STRINGLIST, false),
+ new XSLTAttributeDef(
+ null, "functions", XSLTAttributeDef.T_STRINGLIST, false) },
+ new ProcessorLRE(), ElemExtensionDecl.class /* class object */),
+ exsltFunction, xslFunction/* exslt, stylesheet function*/,
+ xslPrincipalResultDocument}; //end of topevelElements
+
XSLTAttributeDef excludeResultPrefixesAttr =
new XSLTAttributeDef(null, "exclude-result-prefixes",
XSLTAttributeDef.T_STRINGLIST, false);
1.1 xml-xalan/java/src/org/apache/xalan/processor/ProcessorFuncResult.java
Index: ProcessorFuncResult.java
===================================================================
/*
* The Apache Software License, Version 1.1
*
*
* Copyright (c) 1999 The Apache Software Foundation. All rights
* reserved.
*
* 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.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Xalan" and "Apache Software Foundation" must
* not be used to endorse or promote products derived from this
* software without prior written permission. For written
* permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache",
* nor may "Apache" appear in their name, without prior written
* permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED 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 APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS 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.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation and was
* originally based on software copyright (c) 1999, Lotus
* Development Corporation., http://www.lotus.com. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
package org.apache.xalan.processor;
import org.apache.xalan.templates.ElemTemplateElement;
import org.apache.xalan.templates.ElemFunction;
import org.apache.xalan.templates.ElemFuncResult;
import org.apache.xalan.templates.ElemVariable;
import org.apache.xalan.templates.ElemParam;
import org.apache.xalan.templates.ElemFallback;
import org.apache.xalan.res.XSLTErrorResources;
import javax.xml.transform.TransformerException;
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import java.lang.reflect.Method;
import java.lang.reflect.InvocationTargetException;
import java.lang.NoSuchMethodException;
import java.lang.InstantiationException;
import java.lang.IllegalAccessException;
import java.util.Vector;
/**
* <meta name="usage" content="internal"/>
* This class processes parse events for an exslt func:result element.
*/
public class ProcessorFuncResult extends ProcessorTemplateElem
{
/**
* Verify that the parent of xsl:result is an xsl:function element.
*/
public void startElement(
StylesheetHandler handler, String uri, String localName, String rawName, Attributes attributes)
throws SAXException
{
String msg = "";
super.startElement(handler, uri, localName, rawName, attributes);
ElemTemplateElement parent = handler.getElemTemplateElement().getParentElem();
if (!(parent instanceof ElemFunction))
{
msg = "xsl:result must be the last child of an xsl:function element";
handler.error(msg, new SAXException(msg));
}
}
}
1.1 xml-xalan/java/src/org/apache/xalan/processor/ProcessorFunction.java
Index: ProcessorFunction.java
===================================================================
/*
* The Apache Software License, Version 1.1
*
*
* Copyright (c) 1999 The Apache Software Foundation. All rights
* reserved.
*
* 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.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Xalan" and "Apache Software Foundation" must
* not be used to endorse or promote products derived from this
* software without prior written permission. For written
* permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache",
* nor may "Apache" appear in their name, without prior written
* permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED 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 APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS 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.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation and was
* originally based on software copyright (c) 1999, Lotus
* Development Corporation., http://www.lotus.com. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
package org.apache.xalan.processor;
import org.apache.xalan.templates.ElemLiteralResult;
import org.apache.xalan.templates.ElemElement;
import org.apache.xalan.templates.ElemTemplateElement;
import org.apache.xalan.templates.Stylesheet;
import org.apache.xalan.templates.ElemExtensionCall;
import org.apache.xalan.templates.ElemTemplate;
import org.apache.xalan.templates.ElemFunction;
import org.apache.xalan.templates.ElemFuncResult;
import org.apache.xalan.templates.ElemFallback;
import org.apache.xalan.templates.ElemVariable;
import org.apache.xalan.templates.ElemParam;
import org.apache.xalan.templates.ElemValueOf;
import org.apache.xalan.templates.ElemMessage;
import org.apache.xalan.templates.ElemComment;
import org.apache.xalan.templates.Constants;
import org.apache.xpath.XPath;
import org.apache.xalan.templates.StylesheetRoot;
import javax.xml.transform.SourceLocator;
import javax.xml.transform.TransformerException;
import javax.xml.transform.TransformerConfigurationException;
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.apache.xalan.res.XSLTErrorResources;
/**
* <meta name="usage" content="internal"/>
* This class processes parse events for an exslt func:function element.
*/
public class ProcessorFunction extends ProcessorTemplateElem
{
/**
* Start an ElemFunction. Verify that it is top level and that it has a name attribute with a
* namespace.
*/
public void startElement(
StylesheetHandler handler, String uri, String localName, String rawName, Attributes attributes)
throws SAXException
{
//System.out.println("ProcessorFunction.startElement()");
String msg = "";
if (!(handler.getElemTemplateElement() instanceof StylesheetRoot))
{
msg = "func:function element must be top level.";
handler.error(msg, new SAXException(msg));
}
super.startElement(handler, uri, localName, rawName, attributes);
String val = attributes.getValue("name");
int indexOfColon = val.indexOf(":");
if (indexOfColon > 0)
{
String prefix = val.substring(0, indexOfColon);
String localVal = val.substring(indexOfColon + 1);
String ns = handler.getNamespaceSupport().getURI(prefix);
//if (ns.length() > 0)
// System.out.println("fullfuncname " + ns + localVal);
}
else
{
msg = "xsl:function name must have namespace";
handler.error(msg, new SAXException(msg));
}
}
/**
* Must include; super doesn't suffice!
*/
protected void appendAndPush(
StylesheetHandler handler, ElemTemplateElement elem)
throws SAXException
{
//System.out.println("ProcessorFunction appendAndPush()" + elem);
super.appendAndPush(handler, elem);
//System.out.println("originating node " + handler.getOriginatingNode());
elem.setDOMBackPointer(handler.getOriginatingNode());
handler.getStylesheet().setTemplate((ElemTemplate) elem);
}
/**
* End an ElemFunction, and verify its validity.
*/
public void endElement(
StylesheetHandler handler, String uri, String localName, String rawName)
throws SAXException
{
ElemTemplateElement function = handler.getElemTemplateElement();
SourceLocator locator = handler.getLocator();
// Validate
validate(function, handler);// may throw exception
super.endElement(handler, uri, localName, rawName);
}
/**
* Validate that the xsl:function contains children in the following order:
* xsl:param*, xsl:variable* | xsl:message*, xsl:result. The only required
* element is xsl:result, which must be the last child.
* Note: I assume xsl:comment is allowed anywhere.
*/
public void validate(ElemTemplateElement elem, StylesheetHandler handler)
throws SAXException
{
String msg = "";
int result = 0; // Number of xsl:result elements.
int elemOrder = 0;
int lastElemOrder = 0;
boolean invalid = false;
elem = elem.getFirstChildElem();
while (elem != null)
{
if (elem.getXSLToken() == Constants.ELEMNAME_PARAMVARIABLE)
elemOrder = 0;
else if (elem.getXSLToken() == Constants.ELEMNAME_VARIABLE ||
elem.getXSLToken() == Constants.ELEMNAME_MESSAGE)
elemOrder = 1;
else if (elem.getXSLToken() == Constants.ELEMNAME_FUNCRESULT)
{
elemOrder = 2;
if (++result > 1)
{
msg = "xsl:function cannot contain more than one xsl:result element.";
invalid = true;
}
}
else if (elem.getXSLToken() != Constants.ELEMNAME_COMMENT)
{
msg = "xsl:function contains invalid content.";
invalid = true;
}
if (elemOrder < lastElemOrder)
{
msg = "xsl:function elements do not appear in the proper order.";
invalid = true;
}
elem = elem.getNextSiblingElem();
lastElemOrder = elemOrder;
}
if (result != 1)
{
msg = "The last element in an xsl:function must be an xsl:result.";
invalid = true;
}
if (invalid)
handler.error(msg, new SAXException(msg));
}
}
1.1 xml-xalan/java/src/org/apache/xalan/processor/ProcessorResultDocument.java
Index: ProcessorResultDocument.java
===================================================================
/*
* The Apache Software License, Version 1.1
*
*
* Copyright (c) 1999 The Apache Software Foundation. All rights
* reserved.
*
* 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.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Xalan" and "Apache Software Foundation" must
* not be used to endorse or promote products derived from this
* software without prior written permission. For written
* permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache",
* nor may "Apache" appear in their name, without prior written
* permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED 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 APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS 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.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation and was
* originally based on software copyright (c) 1999, Lotus
* Development Corporation., http://www.lotus.com. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
package org.apache.xalan.processor;
import org.apache.xalan.templates.ElemTemplateElement;
import org.apache.xalan.res.XSLTErrorResources;
import javax.xml.transform.TransformerException;
import org.xml.sax.Attributes;
import java.lang.reflect.Method;
import java.lang.reflect.InvocationTargetException;
import java.lang.NoSuchMethodException;
import java.lang.InstantiationException;
import java.lang.IllegalAccessException;
import java.util.Vector;
import org.apache.xml.utils.QName;
import org.apache.xalan.templates.Constants;
import org.apache.xalan.templates.*;
/**
* This class processes parse events for an XSLT template element.
* @see <a href="http://www.w3.org/TR/xslt#dtd">XSLT DTD</a>
* @see <a href="http://www.w3.org/TR/xslt#section-Creating-the-Result-Tree">section-Creating-the-Result-Tree in XSLT Specification</a>
*/
public class ProcessorResultDocument extends ProcessorTemplateElem
{
public void startElement(
StylesheetHandler handler, String uri, String localName, String rawName, Attributes attributes)
throws org.xml.sax.SAXException
{
super.startElement(handler, uri, localName, rawName, attributes);
// validate? Cannot be owned by variable, parameter, message, what else?
if (localName.equals(Constants.ELEMNAME_PRINCIPALRESULTDOCUMENT_STRING))
validatePrincipal(handler);
}
public void endElement(
StylesheetHandler handler, String uri, String localName, String rawName)
throws org.xml.sax.SAXException
{
super.endElement(handler, uri, localName, rawName);
// validate??
}
/**
* This element must be a child of the Stylesheet.
*/
private void validatePrincipal(StylesheetHandler handler)
throws org.xml.sax.SAXException
{
ElemTemplateElement parent = handler.getElemTemplateElement().getParentElem();
//System.out.println("validatePrincipal parent " + parent);
if (!(parent instanceof StylesheetRoot))
{
String msg = "xsl:principal-result-document must be a top-level element.";
handler.error(msg, new org.xml.sax.SAXException(msg));
}
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: xalan-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: xalan-cvs-help@xml.apache.org