mmidy 00/08/10 16:30:50
Modified: java/src/org/apache/xalan/templates ElemApplyImport.java
ElemTemplateElement.java StylesheetComposed.java
StylesheetRoot.java TemplateList.java
java/src/org/apache/xalan/transformer TransformerImpl.java
Log:
Miscellaneous fixes for imported and included stylesheets, xsl-applyImport
and xsl-applyTemplate
Revision Changes Path
1.2 +1 -1
xml-xalan/java/src/org/apache/xalan/templates/ElemApplyImport.java
Index: ElemApplyImport.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/src/org/apache/xalan/templates/ElemApplyImport.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- ElemApplyImport.java 2000/06/19 16:52:47 1.1
+++ ElemApplyImport.java 2000/08/10 23:30:47 1.2
@@ -111,7 +111,7 @@
// This will have to change to current template, (which will have
// to be the top of a current template stack).
- transformer.transformNode(null, null, sourceNode, mode);
+ transformer.transformNode(this, null, sourceNode, mode);
}
else // if(null == sourceNode)
{
1.6 +1 -2
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.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- ElemTemplateElement.java 2000/08/08 00:27:32 1.5
+++ ElemTemplateElement.java 2000/08/10 23:30:47 1.6
@@ -445,8 +445,7 @@
*/
public String getSystemId ()
{
- return (null != m_parentNode) ? m_parentNode.getSystemId() : null;
- // return m_parentNode.getSystemId();
+ return this.getStylesheet().getHref();
}
1.6 +3 -3
xml-xalan/java/src/org/apache/xalan/templates/StylesheetComposed.java
Index: StylesheetComposed.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/src/org/apache/xalan/templates/StylesheetComposed.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- StylesheetComposed.java 2000/08/09 17:51:46 1.5
+++ StylesheetComposed.java 2000/08/10 23:30:47 1.6
@@ -110,8 +110,8 @@
return true;
}
- private transient int m_importNumber = -1;
-
+ private int m_importNumber = -1;
+
/**
* Recalculate the number of this stylesheet in the global
* import list.
@@ -567,7 +567,7 @@
throws SAXException
{
int nIncludes = getIncludeCountComposed();
- for(int k = -1; k < nIncludes; k++)
+ for(int k = nIncludes-1; k >= -1; k--)
{
Stylesheet included = (-1 == k) ? this : getIncludeComposed(k);
1.7 +9 -3
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.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- StylesheetRoot.java 2000/08/09 17:51:47 1.6
+++ StylesheetRoot.java 2000/08/10 23:30:48 1.7
@@ -381,6 +381,12 @@
StylesheetComposed imported = getImport(i);
addImports(imported, true);
}
+ n = getIncludeCount();
+ for(int i = 0; i < n; i++)
+ {
+ Stylesheet included = getInclude(i);
+ addImports(included, false);
+ }
m_globalImportList.insertElementAt(this, 0);
}
super.recomposeImports();
@@ -389,7 +395,7 @@
/**
* Get a stylesheet from the global import list.
*/
- protected StylesheetComposed getGlobalImport(int i)
+ public StylesheetComposed getGlobalImport(int i)
{
return (StylesheetComposed)m_globalImportList.elementAt(i);
}
@@ -400,7 +406,7 @@
* the root stylesheet, thus the number will always be 1 or
* greater.
*/
- protected int getGlobalImportCount()
+ public int getGlobalImportCount()
{
return m_globalImportList.size();
}
@@ -413,7 +419,7 @@
* @return The index into the global import list of the given stylesheet,
* or -1 if it is not found (which should never happen).
*/
- protected int getImportNumber(StylesheetComposed sheet)
+ public int getImportNumber(StylesheetComposed sheet)
{
if(this == sheet)
return 0;
1.4 +70 -49
xml-xalan/java/src/org/apache/xalan/templates/TemplateList.java
Index: TemplateList.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/src/org/apache/xalan/templates/TemplateList.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- TemplateList.java 2000/07/05 14:40:32 1.3
+++ TemplateList.java 2000/08/10 23:30:48 1.4
@@ -138,9 +138,9 @@
{
// find the tail of the list
MatchPattern2 matchPat = (MatchPattern2)val;
- ((MatchPattern2)newMatchPat).setNext(matchPat);
- m_patternTable.put(target, newMatchPat);
- /*
+ //((MatchPattern2)newMatchPat).setNext(matchPat);
+ //m_patternTable.put(target, newMatchPat);
+ //*
MatchPattern2 next;
while((next = matchPat.getNext()) != null)
{
@@ -148,7 +148,7 @@
}
// System.out.println("appending: "+target+" to
"+matchPat.getPattern());
matchPat.setNext((MatchPattern2)newMatchPat);
- */
+ //*/
}
}
}
@@ -212,14 +212,19 @@
switch(targetNodeType)
{
case Node.ELEMENT_NODE:
- // String targetName =
m_parserLiaison.getExpandedElementName((Element)targetNode);
- String targetName =
support.getDOMHelper().getLocalNameOfNode(targetNode);
- matchPat = locateMatchPatternList2(targetName, true);
+ {
+ // String targetName =
m_parserLiaison.getExpandedElementName((Element)targetNode);
+ String targetName =
support.getDOMHelper().getLocalNameOfNode(targetNode);
+ matchPat = locateMatchPatternList2(targetName, true);
+ }
break;
case Node.PROCESSING_INSTRUCTION_NODE:
case Node.ATTRIBUTE_NODE:
- matchPat = locateMatchPatternList2(targetNode.getNodeName(), true);
+ {
+ String targetName =
support.getDOMHelper().getLocalNameOfNode(targetNode);
+ matchPat = locateMatchPatternList2(targetName, true);
+ }
break;
case Node.CDATA_SECTION_NODE:
@@ -264,54 +269,70 @@
{
String patterns = matchPat.getPattern();
- if((null != patterns) && !((prevPat != null) &&
prevPat.equals(patterns) &&
- (prevMatchPat.getTemplate().getPriority()
- ==
matchPat.getTemplate().getPriority())) )
+ if(null != patterns)
{
- prevMatchPat = matchPat;
- prevPat = patterns;
-
- // Date date1 = new Date();
- XPath xpath = matchPat.getExpression();
- // System.out.println("Testing score for:
"+targetNode.getNodeName()+
- // " against '"+xpath.m_currentPattern);
- double score = xpath.getMatchScore(support, targetNode);
- // System.out.println("Score for: "+targetNode.getNodeName()+
- // " against '"+xpath.m_currentPattern+
- // "' returned "+score);
-
- if(XPath.MATCH_SCORE_NONE != score)
+ if((prevPat != null) && prevPat.equals(patterns) &&
+ (prevMatchPat.getTemplate().getPriority()
+ == matchPat.getTemplate().getPriority()))
{
- double priorityOfRule
- = (XPath.MATCH_SCORE_NONE != rule.getPriority())
- ? rule.getPriority() : score;
- matchPat.m_priority = priorityOfRule;
- double priorityOfBestMatched = (null != bestMatchedPattern) ?
- bestMatchedPattern.m_priority :
- XPath.MATCH_SCORE_NONE;
- // System.out.println("priorityOfRule: "+priorityOfRule+",
priorityOfBestMatched: "+priorityOfBestMatched);
- if(priorityOfRule > priorityOfBestMatched)
+ // Then we know that this pattern matches also. Since we're
+ // operating in document order, take this one instead of the
+ // old one.
+ if(bestMatchedPattern == prevMatchPat)
{
- if(null != conflicts)
- conflicts.removeAllElements();
- highScore = score;
bestMatchedRule = rule;
bestMatchedPattern = matchPat;
- }
- else if(priorityOfRule == priorityOfBestMatched)
+ }
+ prevMatchPat = matchPat; // make sure this is done after above
check.
+ // TODO, need to add to the conflicts list, I think...
+ }
+ else
+ {
+ prevMatchPat = matchPat;
+ prevPat = patterns;
+
+ // Date date1 = new Date();
+ XPath xpath = matchPat.getExpression();
+ // System.out.println("Testing score for:
"+targetNode.getNodeName()+
+ // " against '"+xpath.m_currentPattern);
+ double score = xpath.getMatchScore(support, targetNode);
+ // System.out.println("Score for: "+targetNode.getNodeName()+
+ // " against '"+xpath.m_currentPattern+
+ // "' returned "+score);
+
+ if(XPath.MATCH_SCORE_NONE != score)
{
- if(null == conflicts)
- conflicts = new Vector(10);
- addObjectIfNotFound(bestMatchedPattern, conflicts);
- conflicts.addElement(matchPat);
- highScore = score;
- bestMatchedRule = rule;
- bestMatchedPattern = matchPat;
+ double priorityOfRule
+ = (XPath.MATCH_SCORE_NONE != rule.getPriority())
+ ? rule.getPriority() : score;
+ matchPat.m_priority = priorityOfRule;
+ double priorityOfBestMatched = (null != bestMatchedPattern) ?
+ bestMatchedPattern.m_priority :
+ XPath.MATCH_SCORE_NONE;
+ // System.out.println("priorityOfRule: "+priorityOfRule+",
priorityOfBestMatched: "+priorityOfBestMatched);
+ if(priorityOfRule > priorityOfBestMatched)
+ {
+ if(null != conflicts)
+ conflicts.removeAllElements();
+ highScore = score;
+ bestMatchedRule = rule;
+ bestMatchedPattern = matchPat;
+ }
+ else if(priorityOfRule == priorityOfBestMatched)
+ {
+ if(null == conflicts)
+ conflicts = new Vector(10);
+ addObjectIfNotFound(bestMatchedPattern, conflicts);
+ conflicts.addElement(matchPat);
+ highScore = score;
+ bestMatchedRule = rule;
+ bestMatchedPattern = matchPat;
+ }
}
- }
- // Date date2 = new Date();
- // m_totalTimePatternMatching+=(date2.getTime() - date1.getTime());
- } // end if(null != patterns)
+ // Date date2 = new Date();
+ // m_totalTimePatternMatching+=(date2.getTime() -
date1.getTime());
+ }
+ } // end if(null != patterns)
} // end if if(targetModeString.equals(mode))
MatchPattern2 nextMatchPat = matchPat.getNext();
1.15 +20 -2
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.14
retrieving revision 1.15
diff -u -r1.14 -r1.15
--- TransformerImpl.java 2000/08/09 20:05:29 1.14
+++ TransformerImpl.java 2000/08/10 23:30:49 1.15
@@ -1049,13 +1049,31 @@
{
int nodeType = child.getNodeType();
+ boolean isApplyImports = ((xslInstruction == null)? false :
+ xslInstruction.getXSLToken() ==
Constants.ELEMNAME_APPLY_IMPORTS);
+
// To find templates, use the the root of the import tree if
// this element is not an xsl:apply-imports or starting from the root,
// otherwise use the root of the stylesheet tree.
// TODO: Not sure apply-import handling is correct right now. -sb
- StylesheetComposed stylesheetTree = (null == template)
+ StylesheetComposed stylesheetTree;
+ if (isApplyImports)
+ {
+ StylesheetComposed stylesheet = xslInstruction.getStylesheetComposed();
+ StylesheetRoot sroot = stylesheet.getStylesheetRoot();
+ int importNumber = sroot.getImportNumber(stylesheet);
+ int nImports = sroot.getGlobalImportCount();
+ if (importNumber < (nImports - 1))
+ stylesheetTree = sroot.getGlobalImport(importNumber+1);
+ else
+ return false;
+ }
+ else
+ {
+ stylesheetTree = (null == template)
? getStylesheet()
: template.getStylesheetComposed();
+ }
XPathContext xctxt = getXPathContext();
boolean isDefaultTextRule = false;
@@ -1070,7 +1088,7 @@
xctxt.setNamespaceContext(xslInstruction);
template = stylesheetTree.getTemplateComposed(xctxt,
- child, mode,
+ child, mode,
getQuietConflictWarnings());
}
finally