You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xalan.apache.org by mm...@locus.apache.org on 2000/02/10 20:12:00 UTC

cvs commit: xml-xalan/src/org/apache/xalan/xslt ElemNumber.java

mmidy       00/02/10 11:12:00

  Modified:    src/org/apache/xalan/xslt ElemNumber.java
  Log:
  Fix format handling for xsl:number
  
  Revision  Changes    Path
  1.7       +38 -31    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.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- ElemNumber.java	2000/01/31 08:01:09	1.6
  +++ ElemNumber.java	2000/02/10 19:12:00	1.7
  @@ -686,7 +686,16 @@
       StringBuffer formattedNumber = new StringBuffer();
       int nNumbers = list.length, numberWidth = 1;
       char numberType = '1';
  -    String formatToken, lastSepString = null, lastSep = null;
  +    String formatToken, lastSepString = null, formatTokenString = null;
  +    // If a seperator hasn't been specified, then use "."  
  +    // as a default separator. 
  +    // For instance: [2][1][5] with a format value of "1 "
  +    // should format to "2.1.5 " (I think).
  +    // Otherwise, use the seperator specified in the format string.
  +    // For instance: [2][1][5] with a format value of "01-001. "
  +    // should format to "02-001-005 ".
  +    String lastSep = ".";                
  +    boolean isFirstToken = true;        // true if first token  
   
       String formatValue = (null != m_format_avt)
                            ? m_format_avt.evaluate(processor.getExecContext(), contextNode, this,
  @@ -695,8 +704,9 @@
       if(null == formatValue) formatValue = "1";
   
       NumberFormatStringTokenizer formatTokenizer = new NumberFormatStringTokenizer(formatValue);
  -
  -    // Loop through all the numbers in the list.
  +    
  +	int sepCount = 0;                  // keep track of seperators
  +	// Loop through all the numbers in the list.
       for(int i = 0; i < nNumbers; i++)
       {
         // Loop to the next digit, letter, or separator.
  @@ -712,23 +722,25 @@
             numberType = formatToken.charAt(numberWidth-1);
           }
           // If there is a number format directive ahead, 
  -        // then append the separator.
  +        // then append the formatToken.
           else if(formatTokenizer.isLetterOrDigitAhead())
  -        {
  -          // Record this separator, so it can be used as the 
  -          // next separator, if the next is the last.
  -          // For instance: [2][1][5] with a format value of "1.1 "
  -          // should format to "2.1.5 ".
  -          lastSep = formatToken;
  -          
  -          // Append the separator string...
  +        {          
  +          formatTokenString = formatToken;
  +         
  +          // Append the formatToken string...
             // For instance [2][1][5] with a format value of "1--1. "
             // should format to "2--1--5. " (I guess).
             while(formatTokenizer.nextIsSep())
             {
               formatToken = formatTokenizer.nextToken();
  -            lastSep += formatToken;
  +            formatTokenString += formatToken;
             }
  +          // Record this separator, so it can be used as the 
  +          // next separator, if the next is the last.
  +          // For instance: [2][1][5] with a format value of "1-1 "
  +          // should format to "2-1-5 ".
  +          if (!isFirstToken)
  +            lastSep = formatTokenString;
             
             // Since we know the next is a number or digit, we get it now.
             formatToken = formatTokenizer.nextToken();
  @@ -737,22 +749,6 @@
           }
           else // only separators left
           {
  -          // If we're not on the last number to be formatted, 
  -          // then append the lastSep value if it is non-null, otherwise
  -          // append the token.
  -          // For instance: [2][1][5] with a format value of "1. "
  -          // should format to "2.1.5. ".
  -          
  -          // If the lastSep hasn't been specified yet, then assume 
  -          // the last token after the number or digit should be 
  -          // used for all remaining separators.
  -          // For instance: [2][1][5] with a format value of "1 "
  -          // should format to "2 1 5 " (I think).
  -          // For instance: [2][1][5] with a format value of "01-001. "
  -          // should format to "02-001-005 ".
  -          if(null == lastSep)
  -            lastSep = formatToken;
  -          
             // Set up the string for the trailing characters after 
             // the last number is formatted (i.e. after the loop).
             lastSepString = formatToken;
  @@ -767,11 +763,22 @@
           
         } // end if(formatTokenizer.hasMoreTokens())
         
  -      if(null != lastSep)
  +      // if this is the first token and there was a prefix
  +      // append the prefix else, append the separator
  +      // For instance, [2][1][5] with a format value of "(1-1.) "
  +      // should format to "(2-1-5.) " (I guess).
  +      if(null != formatTokenString && isFirstToken)
  +      {
  +        formattedNumber.append(formatTokenString);
  +      }  
  +      else if(null != lastSep && !isFirstToken)
           formattedNumber.append(lastSep);
         
         getFormattedNumber(processor, contextNode, numberType, numberWidth, list[i], formattedNumber);
  -    }
  +      isFirstToken = false;              // After the first pass, this should be false
  +        
  +    }// end for loop
  +    
   
       // Check to see if we finished up the format string...