cocoon-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Ochoa Marcelo F." <moc...@ieee.org>
Subject Re: converting xml file to excel
Date Wed, 22 Nov 2000 19:48:34 GMT
<HTML>
Yao, Di wrote:
<BLOCKQUOTE TYPE=CITE>&nbsp;

<P><FONT FACE="Arial"><FONT SIZE=-1>Dear List:</FONT></FONT>
<BR><FONT FACE="Arial"><FONT SIZE=-1>has anyone tried to generate excel
from xml file? If so, could I see some sample code on how to do it? I really
have no clue.</FONT></FONT></BLOCKQUOTE>
&nbsp;There is simple trick to produce xls output from xml. Adds these
lines to cocoon properties:formatter.type.application/vnd.ms-excel = org.apache.cocoon.formatter.TextFormatter
<BR># Excel Formatter
<BR>formatter.application/vnd.ms-excel.MIME-type = application/vnd.ms-excel

<P>&nbsp;&nbsp; And use an stylesheet like this:
<BR>&lt;?xml version="1.0"?>

<P>&lt;!-- Written by Marcelo F. Ochoa "mochoa@exa.unicen.edu.ar" -->

<P>&lt;xsl:stylesheet xmlns:xsl="<A HREF="http://www.w3.org/1999/XSL/Transform">http://www.w3.org/1999/XSL/Transform</A>">

<P>&nbsp; &lt;xsl:template match="/">
<BR>&nbsp;&nbsp; &lt;xsl:processing-instruction name="cocoon-format">type="application/vnd.ms-excel"&lt;/xsl:processing-instruction>
<BR>&nbsp;&nbsp; &lt;html>
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&lt;xsl:for-each
select="sales/name">
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&lt;xsl:sort select="point"
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
data-type="number"
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
order="ascending"/>
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&lt;!-- tabs separated fields -->
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&lt;xsl:value-of select="@id"/>&lt;xsl:text> &lt;/xsl:text>
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&lt;xsl:value-of select="city"/>&lt;xsl:text> &lt;/xsl:text>
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&lt;xsl:value-of select="point"/>&lt;xsl:text> &lt;/xsl:text>
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&lt;xsl:value-of select="stock"/>&lt;xsl:text> &lt;/xsl:text>
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&lt;!-- the above line feed is intentional do not delete -->
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&lt;xsl:text>
<BR>&lt;/xsl:text>
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&lt;/xsl:for-each>
<BR>&nbsp;&nbsp; &lt;/html>
<BR>&nbsp; &lt;/xsl:template>

<P>&lt;/xsl:stylesheet>
<BR>&nbsp;
<BLOCKQUOTE TYPE=CITE><FONT FACE="Arial"><FONT SIZE=-1></FONT></FONT>&nbsp;

<P><FONT FACE="Arial"><FONT SIZE=-1>thanks.</FONT></FONT>
<BR><FONT FACE="Arial"><FONT SIZE=-1>yaodi</FONT></FONT></BLOCKQUOTE>
&nbsp;&nbsp;&nbsp; This stylesheet produces a tab separated output which
Excel automatically convert to xls.&nbsp;&nbsp;&nbsp; Best regards, Marcelo.</HTML>

Mime
View raw message