I have the following output from the XML below:
 
[xml]
<row>
        <sum_total_octets_sec_pct>1311147.01346801346801346801346801346801</sum_total_octets_sec_pct>
 </row>
<row>
        <sum_total_octets_sec_pct>1214770.05218855218855218855218855218855</sum_total_octets_sec_pct>
 </row>
....
 
[xsl applied]
  <xsl:for-each select="*">
   <xsl:variable name="currname"  select="name()"/>
   <xsl:variable name="currvalue" select="."/>
 
   <xsl:variable name="rest" select ="$currvalue - sum(/report//row[position() &lt;= $topNPlus]/*[name() = $currname])"/>
   <xsl:call-template name="restante">
    <xsl:with-param name="colname" select="$currname"/>
    <!--
    <xsl:with-param name="value"   select="$rest"/>
    -->
    <xsl:with-param name="value"   select="sum(/report//row[position() &lt;= $topNPlus]/*[name() = $currname])"/>
   </xsl:call-template>
  </xsl:for-each>
 
The result of the operation select="sum(/report//row[position() &lt;= $topNPlus]/*[name() = $currname]) is a negative number. I was waiting for a positive number!!!
 
Using the xalan parser directly to the xml it works fine.
Perhaps the problem as to with the class that I use to transform the XML.
Here is the complete class:
[code]
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.Transformer;
import javax.xml.transform.Source;
import javax.xml.transform.stream.StreamSource;
import javax.xml.transform.stream.StreamResult;
import javax.xml.transform.TransformerException;
import javax.xml.transform.TransformerConfigurationException;

// Imported java.io classes
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.net.*;
import java.util.Hashtable;
import java.util.StringTokenizer;
import java.util.Enumeration;
import java.beans.*;



/**
 *  Description of the Class
 *
 [EMAIL PROTECTED]     CDias
 [EMAIL PROTECTED]    3 de Julho de 2003
 */
public class DataTransformer {

    //Properties

    private   String                workdir    = "";
    private   String                basePath   = "";
    private   String                htmlresult = "";
    private   String                xmlinput   = "";
    private   String                stylesheet = "";
    private   Hashtable             parameter  = new Hashtable();
    protected PropertyChangeSupport plisteners = new PropertyChangeSupport(this);

    public void addPropertyChangeListener(PropertyChangeListener l) {
        plisteners.addPropertyChangeListener(l);
    }

    public void removePropertyChangeListener(PropertyChangeListener l) {
        plisteners.removePropertyChangeListener(l);
    }

    public void firePropertyChangeEvt(String p_name, String oldState, String newState) {
        plisteners.firePropertyChange(p_name, oldState, newState);
    }


    public void setParameter(String param) {

        StringTokenizer tk = new StringTokenizer(param, "&");
        while (tk.hasMoreTokens()) {
            StringTokenizer tk1   = new StringTokenizer((tk.nextToken()).toString(), "=");
            String          name  = (tk1.nextToken()).toString();
            String          value = (tk1.nextToken()).toString();
            parameter.put(name, value);
        }
    }


    //String xml a transformar

    public void setWorkdir(String dir) {
        System.setProperty("user.dir", dir);
    }

    public void setXmlinput(String xml) {
        this.xmlinput = new String(xml);
    }

    //Desvolve a string currende de xml que se pretende transformar

    public String getXmlinput() {
        return new String(xmlinput);
    }

    //Set do nome do ficheiro que processa a stylesheet

    public void setStylesheet(String ssh) {
        this.stylesheet = ssh;
    }

    public void setBasePath(String bp) {
        basePath = bp;
    }

    //Devolve o nome da stylesheet que esta a ser usada

    public String getStylesheet() {
        return new String(stylesheet);
    }

    //Devolve o html corresponde ao xml de acordo com a stylesheet que esta a ser usada no momento

    public String getHtmlresult() throws TransformerException, TransformerConfigurationException {
        String media = null;
        String title = null;
        String charset = null;
        try {
            //firePropertyChangeEvt("XMLSTART",new java.util.Date().toString(),"");
            byte                  b[]           = xmlinput.getBytes();
            InputStream           ba          = new ByteArrayInputStream(b);
            StreamSource          sc          = new StreamSource(ba);
            TransformerFactory    tFactory    = TransformerFactory.newInstance();

            Source                xslSource   = new StreamSource(new URL(stylesheet).openStream());

            xslSource.setSystemId(basePath);

            //DEBUG
            Transformer           transformer = tFactory.newTransformer(xslSource);//


            //Inicializar parametros para a Stylesheet

            Enumeration           chaves      = parameter.keys();

            while (chaves.hasMoreElements()) {
                String c = (String) chaves.nextElement();
                String v = (String) parameter.get(c);
                transformer.setParameter(c.trim(), v.trim());
            }

            parameter.clear();//Clean up Hashtable

            ByteArrayOutputStream os          = new ByteArrayOutputStream();
            transformer.transform(sc, new StreamResult(os));
            //DEBUG
            firePropertyChangeEvt("XMLEND", new java.util.Date().toString(), "");
            return (os.toString()).trim();
        } catch (Exception e) {
            e.printStackTrace();
            throw new TransformerException(e.getMessage());
        }

    }
}
[code]
 

Can anybody tell me what's going on?!

I'm using jaxp1.1 (I think) under tomcat 3.2.4 in a Linux envairoment.

Thanks in advance,
Carlos Dias

Reply via email to