mmidy 00/02/11 13:55:37
Modified: src/org/apache/xalan/xslt ElemNumber.java
Log:
Fix problems with matching patterns.
Revision Changes Path
1.8 +30 -23 xml-xalan/src/org/apache/xalan/xslt/ElemNumber.java
Index: ElemNumber.java
===================================================================
RCS file: /home/cvs/xml-xalan/src/org/apache/xalan/xslt/ElemNumber.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- ElemNumber.java 2000/02/10 19:12:00 1.7
+++ ElemNumber.java 2000/02/11 21:55:36 1.8
@@ -72,7 +72,7 @@
* Only nodes are counted that match this pattern.
*/
public XPath m_countMatchPattern = null;
-
+
/**
* Specifies where to count from.
* For level="single" or level="multiple":
@@ -289,7 +289,7 @@
{
if(fromMatchPattern.getMatchScore(execContext, context) !=
XPath.MATCH_SCORE_NONE)
{
- context = null;
+ //context = null;
break;
}
}
@@ -355,6 +355,15 @@
}
return context;
}
+
+ /**
+ * Get the count match pattern, or a default value.
+ */
+ XPath getCountMatchPattern()
+ throws org.xml.sax.SAXException
+ {
+ return m_countMatchPattern;
+ }
/**
* Get the count match pattern, or a default value.
@@ -387,7 +396,6 @@
countMatchPattern =
m_stylesheet.createMatchPattern("pi("+contextNode.getNodeName()+")", this);
break;
}
- m_countMatchPattern = countMatchPattern;
}
return countMatchPattern;
}
@@ -522,16 +530,10 @@
XPath countMatchPattern = getCountMatchPattern(sourceNode);
if(Constants.NUMBERLEVEL_ANY == m_level)
{
- if(null != m_fromMatchPattern)
- {
- target= findPrecedingOrAncestorOrSelf(execContext,
m_fromMatchPattern,
+ target= findPrecedingOrAncestorOrSelf(execContext, m_fromMatchPattern,
countMatchPattern,
sourceNode, this);
- }
- else
- {
- target = sourceNode;
- }
+
}
else
{
@@ -558,29 +560,34 @@
throws org.xml.sax.SAXException
{
MutableNodeList ancestors = new MutableNodeListImpl();
+ XPath countMatchPattern = getCountMatchPattern(node);
while( null != node )
{
if((null != m_fromMatchPattern) &&
(m_fromMatchPattern.getMatchScore(execContext, node) !=
XPath.MATCH_SCORE_NONE))
- break;
+ {
+ // The following if statement gives level="single" different
+ // behavior from level="multiple", which seems incorrect according
+ // to the XSLT spec. For now we are leaving this in to replicate
+ // the same behavior in XT, but, for all intents and purposes we
+ // think this is a bug, or there is something about level="single"
+ // that we still don't understand.
+ if(!stopAtFirstFound)
+ break;
+ }
- if(null != m_countMatchPattern)
- {
- if(m_countMatchPattern.getMatchScore(execContext, node) !=
- XPath.MATCH_SCORE_NONE)
- {
- ancestors.addNode(node);
- if(stopAtFirstFound)
- break;
- }
- }
- else
+ if(null == countMatchPattern)
+ System.out.println("Programmers error! countMatchPattern should
never be null!");
+
+ if(countMatchPattern.getMatchScore(execContext, node) !=
+ XPath.MATCH_SCORE_NONE)
{
ancestors.addNode(node);
if(stopAtFirstFound)
break;
}
+
node = execContext.getParentOfNode(node);
}
return ancestors;