sboag 00/10/03 08:41:13
Modified: java/samples/TransformToDom foo.xml foo.xsl
java/src/org/apache/xalan/processor ProcessorLRE.java
XSLTAttributeDef.java XSLTSchema.java
java/src/org/apache/xalan/templates Constants.java
ElemExtensionCall.java ElemTemplateElement.java
StylesheetRoot.java
java/src/org/apache/xalan/transformer TransformerImpl.java
Log:
Ongoing work for extensions, esp. the component/script elements. Not done
yet. Also, fixed problem with class loading in jview in the serialize package.
Revision Changes Path
1.2 +67 -2 xml-xalan/java/samples/TransformToDom/foo.xml
Index: foo.xml
===================================================================
RCS file: /home/cvs/xml-xalan/java/samples/TransformToDom/foo.xml,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- foo.xml 2000/07/27 16:48:32 1.1
+++ foo.xml 2000/10/03 15:41:07 1.2
@@ -1,2 +1,67 @@
-<?xml version="1.0"?>
-<doc>Hello</doc>
\ No newline at end of file
+<upload>
+ <day>
+ <dow>tue</dow>
+ <order>
+ <line>
+ <product>Belt</product>
+ <price>5.54</price>
+ </line>
+ </order>
+ </day>
+ <day>
+ <dow>wed</dow>
+ </day>
+ <day>
+ <dow>thu</dow>
+ <order>
+ <line>
+ <product>Boots</product>
+ <price>9.23</price>
+ </line>
+ </order>
+ </day>
+ <day>
+ <dow>fri</dow>
+ <order>
+ </order>
+ <order>
+ </order>
+ </day>
+ <day>
+ <dow>sat</dow>
+ <order>
+ <line>
+ <product>Jacket</product>
+ <price>9.84</price>
+ </line>
+ </order>
+ </day>
+ <day>
+ <dow>mon</dow>
+ <order>
+ </order>
+ <order>
+ <line>
+ <product>Tie</product>
+ <price>5.37</price>
+ </line>
+ </order>
+ </day>
+ <day>
+ <dow>tue</dow>
+ </day>
+ <day>
+ <dow>wed</dow>
+ <order>
+ </order>
+ </day>
+ <day>
+ <dow>thu</dow>
+ <order>
+ <line>
+ <product>Overalls</product>
+ <price>3.16</price>
+ </line>
+ </order>
+ </day>
+</upload>
1.2 +68 -5 xml-xalan/java/samples/TransformToDom/foo.xsl
Index: foo.xsl
===================================================================
RCS file: /home/cvs/xml-xalan/java/samples/TransformToDom/foo.xsl,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- foo.xsl 2000/07/27 16:48:32 1.1
+++ foo.xsl 2000/10/03 15:41:07 1.2
@@ -1,6 +1,69 @@
-<?xml version="1.0"?>
-<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
- <xsl:template match="doc">
- <out><xsl:value-of select="."/></out>
- </xsl:template>
+<xsl:stylesheet
+ xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"
+ xmlns="http://www.w3.org/TR/REC-html40">
+
+ <!-- FileName: misc-evans -->
+ <!-- Document: http://www.w3.org/TR/xslt -->
+ <!-- DocVersion: 19991116 -->
+ <!-- Purpose: COPY of perf test;"A Practical Suggestion for XSLT
Performance Improvement" by Clark Evans. -->
+
+ <xsl:variable name="day-list"
+ select="//dow[not(.=following::dow)]" />
+
+ <xsl:variable name="product-list"
+ select="//product[not(.=following::product)]" />
+
+<xsl:template match="/">
+ <xsl:variable name="my-test"><a><b/></a></xsl:variable>
+ <html>
+ <xsl:copy-of select="$my-test"/>
+ <body>
+ <table>
+ <tr>
+ <td><xsl:text> </xsl:text></td>
+ <xsl:for-each select="$day-list">
+ <xsl:sort order="ascending" select="." />
+ <th><xsl:value-of select="."/></th>
+ </xsl:for-each>
+ </tr>
+ <xsl:for-each select="$product-list">
+ <xsl:sort order="ascending" select="." />
+ <xsl:variable name="product" select="." />
+ <tr>
+ <td>
+ <xsl:value-of select="$product" />
+ </td>
+ <xsl:for-each select="$day-list">
+ <xsl:sort order="ascending" select="." />
+ <xsl:variable name="day" select="." />
+ <td>
+ <xsl:value-of
+ select="sum(//price[../product=$product][../../../dow=$day])"
+/> .
+ </td>
+ </xsl:for-each>
+ <td>
+ <xsl:value-of
+ select="sum(//price[../product=$product])" /> .
+ </td>
+ </tr>
+ </xsl:for-each>
+ <tr>
+ <td><xsl:text> </xsl:text></td>
+ <xsl:for-each select="$day-list">
+ <xsl:sort order="ascending" select="." />
+ <xsl:variable name="day" select="." />
+ <td>
+ <xsl:value-of
+ select="sum(//price[../../../dow=$day])" />
+ </td>
+ </xsl:for-each>
+ <td>
+ <xsl:value-of select="sum(//price)" />
+ </td>
+ </tr>
+ </table>
+ </body>
+ </html>
+</xsl:template>
</xsl:stylesheet>
1.5 +21 -0
xml-xalan/java/src/org/apache/xalan/processor/ProcessorLRE.java
Index: ProcessorLRE.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/src/org/apache/xalan/processor/ProcessorLRE.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- ProcessorLRE.java 2000/10/02 23:42:33 1.4
+++ ProcessorLRE.java 2000/10/03 15:41:08 1.5
@@ -61,6 +61,7 @@
import org.apache.xalan.templates.Stylesheet;
import org.apache.xalan.templates.ElemExtensionCall;
import org.apache.xalan.templates.ElemTemplate;
+import org.apache.xalan.templates.Constants;
import org.apache.xpath.XPath;
import org.apache.xalan.templates.StylesheetRoot;
import org.xml.sax.SAXException;
@@ -111,6 +112,8 @@
Class classObject = def.getClassObject();
boolean isExtension = false;
+ boolean isComponentDecl = false;
+ boolean isUnknownTopLevel = false;
while(null != p)
{
// System.out.println("Checking: "+p);
@@ -123,6 +126,14 @@
{
Stylesheet parentElem = (Stylesheet)p;
isExtension = parentElem.containsExtensionElementURI(uri);
+ if((false == isExtension) && (null != uri) &&
uri.equals(Constants.S_BUILTIN_EXTENSIONS_URL))
+ {
+ isComponentDecl = true;
+ }
+ else
+ {
+ isUnknownTopLevel = true;
+ }
}
if(isExtension)
break;
@@ -137,8 +148,18 @@
// System.out.println("Creating extension(1): "+uri);
elem = new ElemExtensionCall();
}
+ else if(isComponentDecl)
+ {
+ }
+ else if(isUnknownTopLevel)
+ {
+ // TBD: Investigate, not sure about this. -sb
+ elem = (ElemLiteralResult)classObject.newInstance();
+ }
else
+ {
elem = (ElemLiteralResult)classObject.newInstance();
+ }
elem.setDOMBackPointer(handler.getOriginatingNode());
elem.setLocaterInfo(handler.getLocator());
elem.setPrefixes(handler.getNamespaceSupport());
1.7 +1 -1
xml-xalan/java/src/org/apache/xalan/processor/XSLTAttributeDef.java
Index: XSLTAttributeDef.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/src/org/apache/xalan/processor/XSLTAttributeDef.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- XSLTAttributeDef.java 2000/08/07 21:29:34 1.6
+++ XSLTAttributeDef.java 2000/10/03 15:41:08 1.7
@@ -503,7 +503,7 @@
}
/**
- * Process an attribute string of type T_STRINGLIST into
+ * Process an attribute string of type T_URLLIST into
* a vector of XPath match patterns.
*/
StringVector processPREFIX_URLLIST(StylesheetHandler handler,
1.9 +26 -1
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.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- XSLTSchema.java 2000/08/31 16:29:45 1.8
+++ XSLTSchema.java 2000/10/03 15:41:08 1.9
@@ -614,7 +614,32 @@
null /* elements */, // EMPTY
new XSLTAttributeDef[] {stylesheetPrefixAttr, resultPrefixAttr},
new ProcessorNamespaceAlias(),
- null /* class object */ )
+ null /* class object */ ),
+
+ new XSLTElementDef(Constants.S_BUILTIN_EXTENSIONS_URL,
+ "component",
+ null /*alias */,
+ new XSLTElementDef[]
+ {
+ new XSLTElementDef(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 */ )
+ }, // 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 */ )
+
};
XSLTAttributeDef excludeResultPrefixesAttr
1.3 +3 -1
xml-xalan/java/src/org/apache/xalan/templates/Constants.java
Index: Constants.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/src/org/apache/xalan/templates/Constants.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- Constants.java 2000/07/05 14:39:51 1.2
+++ Constants.java 2000/10/03 15:41:09 1.3
@@ -171,13 +171,15 @@
ELEMNAME_TEXTLITERALRESULT = 78,
ELEMNAME_EXTENSIONCALL = 79,
+ ELEMNAME_EXTENSIONDECL = 85,
+ ELEMNAME_EXTENSIONSCRIPT = 86,
ELEMNAME_OUTPUT = 80,
ELEMNAME_COMPONENT = 81,
ELEMNAME_SCRIPT = 82;
- // Next free number: 85
+ // Next free number: 87
/**
* Literals for XSL element names. Note that there are more
1.7 +75 -26
xml-xalan/java/src/org/apache/xalan/templates/ElemExtensionCall.java
Index: ElemExtensionCall.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/src/org/apache/xalan/templates/ElemExtensionCall.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- ElemExtensionCall.java 2000/08/09 04:26:40 1.6
+++ ElemExtensionCall.java 2000/10/03 15:41:10 1.7
@@ -84,12 +84,13 @@
{
// ExtensionNSHandler nsh;
String m_extns;
- String m_extHandlerLookup;
+ // String m_extHandlerLookup;
transient boolean isAvailable = false;
String m_lang;
String m_srcURL;
String m_scriptSrc;
Class m_javaClass = null;
+ ElemExtensionDecl m_decl = null;
/**
* Get an int constant identifying the type of element.
@@ -116,6 +117,78 @@
{
return isAvailable;
}
+
+ /**
+ * This function is called after everything else has been
+ * recomposed, and allows the template to set remaining
+ * values that may be based on some other property that
+ * depends on recomposition.
+ */
+ public void compose()
+ {
+ m_extns = this.getNamespace();
+
+ StylesheetRoot stylesheet = this.getStylesheetRoot();
+
+ m_decl = getElemExtensionDecl(stylesheet, m_extns);
+
+ if(null != m_decl)
+ {
+ for(ElemTemplateElement child = m_decl.getFirstChildElem();
+ child != null; child = child.getNextSiblingElem())
+ {
+ if(Constants.ELEMNAME_EXTENSIONSCRIPT == child.getXSLToken())
+ {
+ ElemExtensionScript sdecl = (ElemExtensionScript)child;
+ m_lang = sdecl.getLang();
+ m_srcURL = sdecl.getSrc();
+ ElemTemplateElement childOfSDecl = sdecl.getFirstChildElem();
+ if(null != childOfSDecl)
+ {
+ if(Constants.ELEMNAME_TEXTLITERALRESULT ==
childOfSDecl.getXSLToken())
+ {
+ ElemTextLiteral tl = (ElemTextLiteral)childOfSDecl;
+ char[] chars = tl.getChars();
+ m_scriptSrc = new String(chars);
+ }
+ }
+ break;
+ }
+ }
+
+ }
+ else
+ {
+ // stylesheet.error(xxx);
+ }
+ }
+
+ private ElemExtensionDecl getElemExtensionDecl(StylesheetRoot stylesheet,
+ String namespace)
+ {
+ ElemExtensionDecl decl = null;
+
+ int n = stylesheet.getImportCountComposed();
+ for(int i = 0; i < n; i++)
+ {
+ Stylesheet imported = stylesheet.getImportComposed(i);
+ for(ElemTemplateElement child = imported.getFirstChildElem();
+ child != null; child = child.getNextSiblingElem())
+ {
+ if(Constants.ELEMNAME_EXTENSIONDECL == child.getXSLToken())
+ {
+ decl = (ElemExtensionDecl)child;
+ String prefix = decl.getPrefix();
+ String declNamespace = child.getNamespaceForPrefix(prefix);
+ if(namespace.equals(declNamespace))
+ {
+ return decl;
+ }
+ }
+ }
+ }
+ return decl;
+ }
/**
* Execute an extension.
@@ -129,33 +202,9 @@
{
transformer.getResultTreeHandler().flushPending();
- ExtensionNSHandler nsh = null;
- if(null == m_extns)
- {
- m_extns = this.getNamespace();
- nsh = new ExtensionNSHandler (m_extns);
- m_lang = nsh.scriptLang;
- m_srcURL = nsh.scriptSrcURL;
- m_scriptSrc = nsh.scriptSrc;
-
- // System.out.println("localName: "+this.getLocalName());
- // System.out.println("m_lang: "+m_lang);
- // System.out.println("m_javaClass: "+m_javaClass);
- // System.out.println("m_srcURL: "+m_srcURL);
- // System.out.println("m_scriptSrc: "+m_scriptSrc);
- // System.out.println("m_extns: "+m_extns);
- }
-
XPathContext liaison = ((XPathContext)transformer.getXPathContext());
ExtensionsTable etable = liaison.getExtensionsTable();
- nsh = etable.get(m_extns);
-
- if(null == nsh)
- {
- nsh = new ExtensionNSHandler (m_extns);
- nsh.setScript (m_lang, m_srcURL, m_scriptSrc);
- etable.addExtensionElementNamespace(m_extns, nsh);
- }
+ ExtensionNSHandler nsh = etable.get(m_extns);
nsh.processElement (this.getLocalName(), this,
transformer,
1.9 +22 -0
xml-xalan/java/src/org/apache/xalan/templates/ElemTemplateElement.java
Index: ElemTemplateElement.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/src/org/apache/xalan/templates/ElemTemplateElement.java,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- ElemTemplateElement.java 2000/10/02 02:43:07 1.8
+++ ElemTemplateElement.java 2000/10/03 15:41:10 1.9
@@ -145,6 +145,18 @@
return "Unknown XSLT Element";
}
+ /**
+ * This function will be called on top-level elements
+ * only, just before the transform begins.
+ *
+ * @param transformer The XSLT Processor.
+ */
+ public void runtimeInit(TransformerImpl transformer)
+ throws SAXException
+ {
+ }
+
+
/** Execute the element's primary function. Subclasses of this
* function may recursivly execute down the element tree.
*
@@ -196,6 +208,16 @@
{
return m_parentNode.getStylesheetRoot();
}
+
+ /**
+ * This function is called after everything else has been
+ * recomposed, and allows the template to set remaining
+ * values that may be based on some other property that
+ * depends on recomposition.
+ */
+ public void compose()
+ {
+ }
/**
* Validate that the string is an NCName.
1.10 +32 -18
xml-xalan/java/src/org/apache/xalan/templates/StylesheetRoot.java
Index: StylesheetRoot.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/src/org/apache/xalan/templates/StylesheetRoot.java,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- StylesheetRoot.java 2000/10/02 23:42:33 1.9
+++ StylesheetRoot.java 2000/10/03 15:41:10 1.10
@@ -181,27 +181,41 @@
if(sheet != this) // already done
{
sheet.recomposeImports();
- sheet.recomposeIncludes(sheet);
- sheet.recomposeAttributeSets();
- sheet.recomposeDecimalFormats();
- sheet.recomposeKeys();
- sheet.recomposeNamespaceAliases();
- sheet.recomposeParams();
- sheet.recomposeTemplates();
- sheet.recomposeVariables();
- sheet.recomposeWhiteSpaceInfo();
+ sheet.recomposeIncludes(sheet);
+ sheet.recomposeAttributeSets();
+ sheet.recomposeDecimalFormats();
+ sheet.recomposeKeys();
+ sheet.recomposeNamespaceAliases();
+ sheet.recomposeParams();
+ sheet.recomposeTemplates();
+ sheet.recomposeVariables();
+ sheet.recomposeWhiteSpaceInfo();
}
}
- recomposeIncludes(this);
- recomposeAttributeSets();
- recomposeDecimalFormats();
- recomposeKeys();
- recomposeNamespaceAliases();
- recomposeParams();
- recomposeTemplates();
- recomposeVariables();
- recomposeWhiteSpaceInfo();
+ recomposeIncludes(this);
+ recomposeAttributeSets();
+ recomposeDecimalFormats();
+ recomposeKeys();
+ recomposeNamespaceAliases();
+ recomposeParams();
+ recomposeTemplates();
+ recomposeVariables();
+ recomposeWhiteSpaceInfo();
+ composeTemplates(this);
+ }
+
+ /**
+ * Call the compose function for each ElemTemplateElement.
+ */
+ void composeTemplates(ElemTemplateElement templ)
+ {
+ templ.compose();
+ for(ElemTemplateElement child = templ.getFirstChildElem();
+ child != null; child = child.getNextSiblingElem())
+ {
+ child.compose();
+ }
}
/**
1.23 +19 -1
xml-xalan/java/src/org/apache/xalan/transformer/TransformerImpl.java
Index: TransformerImpl.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/src/org/apache/xalan/transformer/TransformerImpl.java,v
retrieving revision 1.22
retrieving revision 1.23
diff -u -r1.22 -r1.23
--- TransformerImpl.java 2000/10/02 23:42:34 1.22
+++ TransformerImpl.java 2000/10/03 15:41:12 1.23
@@ -574,6 +574,24 @@
try
{
pushGlobalVars(node);
+
+ // ==========
+ // Give the top-level templates a chance to pass information into
+ // the context (this is mainly for setting up tables for extensions).
+ StylesheetRoot stylesheet = this.getStylesheet();
+ int n = stylesheet.getImportCountComposed();
+ for(int i = 0; i < n; i++)
+ {
+ Stylesheet imported = stylesheet.getImportComposed(i);
+ imported.runtimeInit(this);
+ for(ElemTemplateElement child = imported.getFirstChildElem();
+ child != null; child = child.getNextSiblingElem())
+ {
+ child.runtimeInit(this);
+ }
+ }
+ // ===========
+
this.transformNode(null, null, node, null);
if((null != m_resultTreeHandler) &&
!m_resultTreeHandler.getFoundEndDoc())
{
@@ -845,7 +863,7 @@
Node sourceNode, QName mode)
throws SAXException
{
- XPathContext xctxt = getXPathContext();
+ // XPathContext xctxt = getXPathContext();
// Document docFactory = xctxt.getDOMHelper().getDOMFactory();
if(null == m_docBuilder)