You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cocoon.apache.org by Anna Bikkina <an...@pinksheets.com> on 2004/03/05 17:31:06 UTC
xsl to convert xml to excel
Can someone please answer my question below I am stuck.
On Thursday 04 March 2004 03:41 pm, Anna Bikkina wrote:
> Hi,
>
> I have a xml file that has to converted to excel. I am trying to use a xsl
> s stylesheet and cocoon to do this job for me.
>
> Below is my xml. I am able to display the column's correctly in excel but
> when it comes to data . I am not able to have <Time> data in column1,
> <Action> data in column. I am not able to increment the column value from 0
> to 5. The problem is the number of columns I will have is not known prior .
> So I have to use the count() function to get this done. The way it is
> printing row data right now is in column 5 it prints the value of <user1>
> thats it. Please check the xsl below and let me know where I am making a
> mistake.
>
>
> <xsl:template match="result">
> <xsl:for-each select="column">
> <gmr:Cell Row="0" ValueType="60">
> <xsl:variable name="colnumber"><xsl:number level="any"
> from="result" count="column"/></xsl:variable>
> <xsl:attribute name="Col">
> <xsl:value-of select="$colnumber"/>
> </xsl:attribute>
> <gmr:Content>
> <xsl:apply-templates select="." mode="value"/>
> </gmr:Content>
> </gmr:Cell>
> </xsl:for-each>
>
> <xsl:for-each select="row">
> <xsl:variable name="rownumber"><xsl:number level="any"
> from="result" count="row"/></xsl:variable>
> <xsl:variable name="cnumber"><xsl:number level="any" from="result"
> count="column"/></xsl:variable>
> <xsl:for-each select="*">
>
> <gmr:Cell ValueType="60">
> <xsl:attribute name="Row">
> <xsl:value-of select="$rownumber"/>
> </xsl:attribute>
> <xsl:attribute name="Col">
> <xsl:value-of select="$cnumber"/> <!-- cnumber is not working
> properly. How can I get this working-->
> </xsl:attribute>
> <gmr:Content>
> <xsl:apply-templates select="." mode="value"/>
> </gmr:Content>
> </gmr:Cell>
> </xsl:for-each>
> </xsl:for-each>
>
> </xsl:template>
>
>
> My XML FILE
>
>
> <?xml version="1.0"?>
> <page>
> <title>Hello</title>
> <content>
> <result>
> <column>Time</column>
> <column>Action</column>
> <column>Price</column>
> <column>User</column>
> <column>User1</br></column>
> <row>
> <Time>1</Time>
> <Action>120000</Action>
> <Price>13</Price>
> <Name>12000</Name>
> <Name1>120000</Name1>
> </row>
>
> </result>
> </content>
> </page>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org
Re: xsl to convert xml to excel
Posted by Anna Bikkina <an...@pinksheets.com>.
Nevermind,I got most of it working except that column0 is left blank and the
whole data is printed from column1. Not sure where I am making a mistake.
Can someone help.
here is my latest xsl
<xsl:template match="result">
<xsl:for-each select="column">
<gmr:Cell Row="0" ValueType="60">
<xsl:variable name="colnumber"><xsl:number level="single"
from="column" count="column"/></xsl:variable>
<xsl:attribute name="Col">
<xsl:value-of select="$colnumber"/>
</xsl:attribute>
<gmr:Content>
<xsl:apply-templates select="." mode="value"/>
</gmr:Content>
</gmr:Cell>
</xsl:for-each>
<xsl:for-each select="row">
<xsl:apply-templates select=".">
<xsl:with-param name="rownumber" select="position()"/>
</xsl:apply-templates>
</xsl:for-each>
</xsl:template>
<xsl:template match="row">
<xsl:param name="rownumber" select="1"/>
<xsl:for-each select="*">
<xsl:apply-templates select=".">
<xsl:with-param name="rownumber" select="$rownumber"/>
<xsl:with-param name="colnumber" select="position()"/>
</xsl:apply-templates>
</xsl:for-each>
</xsl:template>
<xsl:template match="*">
<!-- avoids Result Tree Fragments -->
<xsl:param name="rownumber" select="0"/>
<xsl:param name="colnumber" select="0"/>
<gmr:Cell ValueType="60" Col="{$colnumber}" Row="{$rownumber}">
<xsl:value-of select="."/>
</gmr:Cell>
</xsl:template>
Thanks in advance,
Anna.
On Friday 05 March 2004 11:31 am, Anna Bikkina wrote:
> Can someone please answer my question below I am stuck.
>
> On Thursday 04 March 2004 03:41 pm, Anna Bikkina wrote:
> > Hi,
> >
> > I have a xml file that has to converted to excel. I am trying to use a
> > xsl s stylesheet and cocoon to do this job for me.
> >
> > Below is my xml. I am able to display the column's correctly in excel but
> > when it comes to data . I am not able to have <Time> data in column1,
> > <Action> data in column. I am not able to increment the column value from
> > 0 to 5. The problem is the number of columns I will have is not known
> > prior . So I have to use the count() function to get this done. The way
> > it is printing row data right now is in column 5 it prints the value of
> > <user1> thats it. Please check the xsl below and let me know where I am
> > making a mistake.
> >
> >
> > <xsl:template match="result">
> > <xsl:for-each select="column">
> > <gmr:Cell Row="0" ValueType="60">
> > <xsl:variable name="colnumber"><xsl:number level="any"
> > from="result" count="column"/></xsl:variable>
> > <xsl:attribute name="Col">
> > <xsl:value-of select="$colnumber"/>
> > </xsl:attribute>
> > <gmr:Content>
> > <xsl:apply-templates select="." mode="value"/>
> > </gmr:Content>
> > </gmr:Cell>
> > </xsl:for-each>
> >
> > <xsl:for-each select="row">
> > <xsl:variable name="rownumber"><xsl:number level="any"
> > from="result" count="row"/></xsl:variable>
> > <xsl:variable name="cnumber"><xsl:number level="any"
> > from="result" count="column"/></xsl:variable>
> > <xsl:for-each select="*">
> >
> > <gmr:Cell ValueType="60">
> > <xsl:attribute name="Row">
> > <xsl:value-of select="$rownumber"/>
> > </xsl:attribute>
> > <xsl:attribute name="Col">
> > <xsl:value-of select="$cnumber"/> <!-- cnumber is not working
> > properly. How can I get this working-->
> > </xsl:attribute>
> > <gmr:Content>
> > <xsl:apply-templates select="." mode="value"/>
> > </gmr:Content>
> > </gmr:Cell>
> > </xsl:for-each>
> > </xsl:for-each>
> >
> > </xsl:template>
> >
> >
> > My XML FILE
> >
> >
> > <?xml version="1.0"?>
> > <page>
> > <title>Hello</title>
> > <content>
> > <result>
> > <column>Time</column>
> > <column>Action</column>
> > <column>Price</column>
> > <column>User</column>
> > <column>User1</br></column>
> > <row>
> > <Time>1</Time>
> > <Action>120000</Action>
> > <Price>13</Price>
> > <Name>12000</Name>
> > <Name1>120000</Name1>
> > </row>
> >
> > </result>
> > </content>
> > </page>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
> For additional commands, e-mail: users-help@cocoon.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org