zongaro     2004/11/19 08:36:17

  Modified:    java/src/org/apache/xalan/transformer KeyTable.java
  Log:
  Patch for Jira bug 1368.
  
  The method getKeyDeclaration was looping through all the xsl:key elements
  defined, and returning the first with the required name.  However, more than
  one xsl:key element can specify the same name, and should be treated
  cumulatively.  Modified the method so that it returns all elements with the
  required name, and the caller so that it tries to match against the patterns
  associated with all such elements.
  
  Reviewed by Joanne Tong (joannet () ca ! ibm ! com).
  
  Revision  Changes    Path
  1.18      +33 -31    
xml-xalan/java/src/org/apache/xalan/transformer/KeyTable.java
  
  Index: KeyTable.java
  ===================================================================
  RCS file: 
/home/cvs/xml-xalan/java/src/org/apache/xalan/transformer/KeyTable.java,v
  retrieving revision 1.17
  retrieving revision 1.18
  diff -u -r1.17 -r1.18
  --- KeyTable.java     16 Feb 2004 20:41:29 -0000      1.17
  +++ KeyTable.java     19 Nov 2004 16:36:17 -0000      1.18
  @@ -154,26 +154,25 @@
     }
   
     /**
  -   * @return key declaration for the key associated to this KeyTable
  +   * @return key declarations for the key associated to this KeyTable
      */
  -  private KeyDeclaration getKeyDeclaration() {
  +  private Vector getKeyDeclarations() {
       int nDeclarations = m_keyDeclarations.size();
  +    Vector keyDecls = new Vector(nDeclarations);
   
       // Walk through each of the declarations made with xsl:key
       for (int i = 0; i < nDeclarations; i++)
       {
         KeyDeclaration kd = (KeyDeclaration) m_keyDeclarations.elementAt(i);
   
  -      // Only continue if the name on this key declaration
  +      // Add the declaration if the name on this key declaration
         // matches the name on the iterator for this walker.
  -      if (kd.getName().equals(getKeyTableName()))
  -      {
  -        return kd;
  +      if (kd.getName().equals(getKeyTableName())) {
  +        keyDecls.add(kd);
         }
       }
   
  -    // should never happen
  -    return null;
  +    return keyDecls;
     }
   
     /**
  @@ -182,14 +181,15 @@
      */
     private Hashtable getRefsTable()
     {
  -    if (m_refsTable == null)
  -    {
  -      m_refsTable = new Hashtable(89);  // initial capacity set to a prime 
number to improve hash algorithm performance
  +    if (m_refsTable == null) {
  +      // initial capacity set to a prime number to improve hash performance
  +      m_refsTable = new Hashtable(89);
   
         KeyIterator ki = (KeyIterator) (m_keyNodes).getContainedIter();
         XPathContext xctxt = ki.getXPathContext();
   
  -      KeyDeclaration keyDeclaration = getKeyDeclaration();
  +      Vector keyDecls = getKeyDeclarations();
  +      int nKeyDecls = keyDecls.size();
   
         int currentNode;
         m_keyNodes.reset();
  @@ -197,28 +197,30 @@
         {
           try
           {
  -          XObject xuse = keyDeclaration.getUse().execute(xctxt, currentNode, 
ki.getPrefixResolver());
  +          for (int keyDeclIdx = 0; keyDeclIdx < nKeyDecls; keyDeclIdx++) {
  +            KeyDeclaration keyDeclaration =
  +                (KeyDeclaration) keyDecls.elementAt(keyDeclIdx);
  +            XObject xuse =
  +                keyDeclaration.getUse().execute(xctxt,
  +                                                currentNode,
  +                                                ki.getPrefixResolver());
   
  -          if (xuse.getType() != xuse.CLASS_NODESET)
  -          {
  -            XMLString exprResult = xuse.xstr();
  -            addValueInRefsTable(xctxt, exprResult, currentNode);
  -          }
  -          else
  -          {
  -            DTMIterator i = ((XNodeSet)xuse).iterRaw();
  -            int currentNodeInUseClause;
  -
  -            while (DTM.NULL != (currentNodeInUseClause = i.nextNode()))
  -            {
  -              DTM dtm = xctxt.getDTM(currentNodeInUseClause);
  -              XMLString exprResult = 
dtm.getStringValue(currentNodeInUseClause);
  +            if (xuse.getType() != xuse.CLASS_NODESET) {
  +              XMLString exprResult = xuse.xstr();
                 addValueInRefsTable(xctxt, exprResult, currentNode);
  +            } else {
  +              DTMIterator i = ((XNodeSet)xuse).iterRaw();
  +              int currentNodeInUseClause;
  +
  +              while (DTM.NULL != (currentNodeInUseClause = i.nextNode())) {
  +                DTM dtm = xctxt.getDTM(currentNodeInUseClause);
  +                XMLString exprResult =
  +                    dtm.getStringValue(currentNodeInUseClause);
  +                addValueInRefsTable(xctxt, exprResult, currentNode);
  +              }
               }
             }
  -        }
  -        catch (TransformerException te)
  -        {
  +        } catch (TransformerException te) {
             throw new WrappedRuntimeException(te);
           }
         }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to