mmidy 02/01/30 11:08:02
Modified: java/src/org/apache/xalan/templates StylesheetComposed.java
StylesheetRoot.java TemplateList.java
java/src/org/apache/xalan/transformer TransformerImpl.java
Log:
Bug 4987: Changed Apply-imports logic to only apply imports to stylesheets that are
direct imports. The logic for includes has not changed, we will apply-imports to any
stylesheet that is imported as a result of an inclusion. Note: had to change the order
when includes and imports are recomposed!
Revision Changes Path
1.26 +37 -2
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.25
retrieving revision 1.26
diff -u -r1.25 -r1.26
--- StylesheetComposed.java 2 Jan 2001 03:36:47 -0000 1.25
+++ StylesheetComposed.java 30 Jan 2002 19:08:01 -0000 1.26
@@ -126,8 +126,8 @@
public void recompose(Vector recomposableElements) throws TransformerException
{
- recomposeImports(); // Calculate the number of this import.
- recomposeIncludes(this); // Build the global include list for this
stylesheet.
+ //recomposeImports(); // Calculate the number of this import.
+ //recomposeIncludes(this); // Build the global include list for this
stylesheet.
// Now add in all of the recomposable elements at this precedence level
@@ -219,6 +219,9 @@
* @serial
*/
private int m_importCountComposed;
+
+ /* The count of imports composed for this stylesheet */
+ private int m_endImportCountComposed;
/**
* Recalculate the precedence of this stylesheet in the global
@@ -234,6 +237,27 @@
int globalImportCount = root.getGlobalImportCount();
m_importCountComposed = (globalImportCount - m_importNumber) - 1;
+
+ // Now get the count of composed imports from this stylesheet's imports
+ int count = getImportCount();
+ if ( count > 0)
+ {
+ m_endImportCountComposed += count;
+ while (count > 0)
+ m_endImportCountComposed +=
this.getImport(--count).getEndImportCountComposed();
+ }
+
+ // Now get the count of composed imports from this stylesheet's
+ // composed includes.
+ count = getIncludeCountComposed();
+ while (count>0)
+ {
+ int imports = getIncludeComposed(--count).getImportCount();
+ m_endImportCountComposed += imports;
+ while (imports > 0)
+ m_endImportCountComposed
+=getIncludeComposed(count).getImport(--imports).getEndImportCountComposed();
+
+ }
}
/**
@@ -270,6 +294,17 @@
{
return m_importCountComposed;
}
+
+ /**
+ * Get the number of import in this stylesheet's composed list.
+ *
+ * @return the number of imports in this stylesheet's composed list.
+ */
+ public int getEndImportCountComposed()
+ {
+ return m_endImportCountComposed;
+ }
+
/**
* The combined list of includes.
1.46 +47 -10
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.45
retrieving revision 1.46
diff -u -r1.45 -r1.46
--- StylesheetRoot.java 28 Jul 2001 00:25:58 -0000 1.45
+++ StylesheetRoot.java 30 Jan 2002 19:08:01 -0000 1.46
@@ -212,6 +212,9 @@
*/
public void recompose() throws TransformerException
{
+ // Now we make a Vector that is going to hold all of the recomposable elements
+
+ Vector recomposableElements = new Vector();
// First, we build the global import tree.
@@ -220,7 +223,7 @@
Vector importList = new Vector();
- addImports(this, true, importList);
+ addImports(this, true, importList);
// Now we create an array and reverse the order of the importList vector.
// We built the importList vector backwards so that we could use addElement
@@ -230,13 +233,19 @@
m_globalImportList = new StylesheetComposed[importList.size()];
- for (int i = importList.size() - 1, j= 0; i >= 0; i--)
- m_globalImportList[j++] = (StylesheetComposed) importList.elementAt(i);
+ for (int i = 0, j= importList.size() -1; i < importList.size(); i++)
+ {
+ m_globalImportList[j] = (StylesheetComposed) importList.elementAt(i);
+ // Build the global include list for this stylesheet.
+ // This needs to be done ahead of the recomposeImports
+ // because we need the info from the composed includes.
+ m_globalImportList[j].recomposeIncludes(m_globalImportList[j]);
+ // Calculate the number of this import.
+ m_globalImportList[j--].recomposeImports();
+ }
}
- // Now we make a Vector that is going to hold all of the recomposable elements
-
- Vector recomposableElements = new Vector();
+
// Next, we walk the import tree and add all of the recomposable elements to
the vector.
@@ -697,9 +706,37 @@
* @param xctxt non-null reference to XPath runtime execution context.
* @param targetNode non-null reference of node that the template must match.
* @param mode qualified name of the node, or null.
+ * @param quietConflictWarnings true if conflict warnings should not be reported.
+ *
+ * @return reference to ElemTemplate that is the best match for targetNode, or
+ * null if no match could be made.
+ *
+ * @throws TransformerException
+ */
+ public ElemTemplate getTemplateComposed(XPathContext xctxt,
+ int targetNode,
+ QName mode,
+ boolean quietConflictWarnings,
+ DTM dtm)
+ throws TransformerException
+ {
+ return m_templateList.getTemplate(xctxt, targetNode, mode,
+ quietConflictWarnings,
+ dtm);
+ }
+
+ /**
+ * Get an "xsl:template" property by node match. This looks in the imports as
+ * well as this stylesheet.
+ * @see <a
href="http://www.w3.org/TR/xslt#section-Defining-Template-Rules">section-Defining-Template-Rules
in XSLT Specification</a>
+ *
+ * @param xctxt non-null reference to XPath runtime execution context.
+ * @param targetNode non-null reference of node that the template must match.
+ * @param mode qualified name of the node, or null.
* @param maxImportLevel The maximum importCountComposed that we should consider
or -1
* if we should consider all import levels. This is used by apply-imports
to
* access templates that have been overridden.
+ * @param endImportLevel The count of composed imports
* @param quietConflictWarnings true if conflict warnings should not be reported.
*
* @return reference to ElemTemplate that is the best match for targetNode, or
@@ -710,13 +747,13 @@
public ElemTemplate getTemplateComposed(XPathContext xctxt,
int targetNode,
QName mode,
- int maxImportLevel,
+ int maxImportLevel, int endImportLevel,
boolean quietConflictWarnings,
DTM dtm)
throws TransformerException
{
return m_templateList.getTemplate(xctxt, targetNode, mode,
- maxImportLevel,
+ maxImportLevel, endImportLevel,
quietConflictWarnings,
dtm);
}
@@ -842,7 +879,7 @@
if (null != m_whiteSpaceInfoList)
return (WhiteSpaceInfo) m_whiteSpaceInfoList.getTemplate(support,
- targetElement, null, -1, false, dtm);
+ targetElement, null, false, dtm);
else
return null;
}
@@ -867,7 +904,7 @@
{
DTM dtm = support.getDTM(targetElement);
WhiteSpaceInfo info = (WhiteSpaceInfo)
m_whiteSpaceInfoList.getTemplate(support,
- targetElement, null, -1, false, dtm);
+ targetElement, null, false, dtm);
if(null != info)
return info.getShouldStripSpace();
1.32 +65 -2 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.31
retrieving revision 1.32
diff -u -r1.31 -r1.32
--- TemplateList.java 12 Jun 2001 19:15:13 -0000 1.31
+++ TemplateList.java 30 Jan 2002 19:08:01 -0000 1.32
@@ -617,9 +617,70 @@
* @param xctxt
* @param targetNode
* @param mode A string indicating the display mode.
+ * @param quietConflictWarnings
+ * @return Rule that best matches targetElem.
+ * @throws XSLProcessorException thrown if the active ProblemListener and
XPathContext decide
+ * the error condition is severe enough to halt processing.
+ *
+ * @throws TransformerException
+ */
+ public ElemTemplate getTemplate(XPathContext xctxt,
+ int targetNode,
+ QName mode,
+ boolean quietConflictWarnings,
+ DTM dtm)
+ throws TransformerException
+ {
+
+ TemplateSubPatternAssociation head = getHead(xctxt, targetNode, dtm);
+
+ if (null != head)
+ {
+ // XSLT functions, such as xsl:key, need to be able to get to
+ // current ElemTemplateElement via a cast to the prefix resolver.
+ // Setting this fixes bug idkey03.
+ xctxt.pushNamespaceContextNull();
+ xctxt.pushCurrentNodeAndExpression(targetNode, targetNode);
+ try
+ {
+ do
+ {
+ ElemTemplate template = head.getTemplate();
+ xctxt.setNamespaceContext(template);
+
+ if ((head.m_stepPattern.execute(xctxt, targetNode) != NodeTest.SCORE_NONE)
+ && head.matchMode(mode))
+ {
+ if (quietConflictWarnings)
+ checkConflicts(head, xctxt, targetNode, mode);
+
+ return template;
+ }
+ }
+ while (null != (head = head.getNext()));
+ }
+ finally
+ {
+ xctxt.popCurrentNodeAndExpression();
+ xctxt.popNamespaceContext();
+ }
+ }
+
+ return null;
+ } // end findTemplate
+
+ /**
+ * Given a target element, find the template that best
+ * matches in the given XSL document, according
+ * to the rules specified in the xsl draft.
+ *
+ * @param xctxt
+ * @param targetNode
+ * @param mode A string indicating the display mode.
* @param maxImportLevel The maximum importCountComposed that we should consider
or -1
* if we should consider all import levels. This is used by apply-imports
to
* access templates that have been overridden.
+ * @param maxEndImportLevel The count of composed imports
* @param quietConflictWarnings
* @return Rule that best matches targetElem.
* @throws XSLProcessorException thrown if the active ProblemListener and
XPathContext decide
@@ -630,7 +691,7 @@
public ElemTemplate getTemplate(XPathContext xctxt,
int targetNode,
QName mode,
- int maxImportLevel,
+ int maxImportLevel, int endImportLevel,
boolean quietConflictWarnings,
DTM dtm)
throws TransformerException
@@ -649,10 +710,12 @@
{
do
{
- if ( (maxImportLevel > -1) && (head.getImportLevel() > maxImportLevel) )
+ if ( (maxImportLevel > -1) && (head.getImportLevel() > maxImportLevel))
{
continue;
}
+ if (head.getImportLevel()<= maxImportLevel - endImportLevel)
+ return null;
ElemTemplate template = head.getTemplate();
xctxt.setNamespaceContext(template);
1.121 +11 -4
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.120
retrieving revision 1.121
diff -u -r1.120 -r1.121
--- TransformerImpl.java 28 Jan 2002 22:18:16 -0000 1.120
+++ TransformerImpl.java 30 Jan 2002 19:08:01 -0000 1.121
@@ -1949,7 +1949,7 @@
if (null == template)
{
- int maxImportLevel;
+ int maxImportLevel, endImportLevel=0;
boolean isApplyImports = ((xslInstruction == null)
? false
: xslInstruction.getXSLToken()
@@ -1959,6 +1959,8 @@
{
maxImportLevel =
xslInstruction.getStylesheetComposed().getImportCountComposed() - 1;
+ endImportLevel =
+ xslInstruction.getStylesheetComposed().getEndImportCountComposed();
}
else
{
@@ -1987,9 +1989,14 @@
xctxt.pushNamespaceContext(xslInstruction);
QName mode = this.getMode();
-
- template = m_stylesheetRoot.getTemplateComposed(xctxt, child, mode,
- maxImportLevel, m_quietConflictWarnings, dtm);
+
+ if (isApplyImports)
+ template = m_stylesheetRoot.getTemplateComposed(xctxt, child, mode,
+ maxImportLevel, endImportLevel, m_quietConflictWarnings, dtm);
+ else
+ template = m_stylesheetRoot.getTemplateComposed(xctxt, child, mode,
+ m_quietConflictWarnings, dtm);
+
}
finally
{
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]