xsl-list
[Top] [All Lists]

Re: XSL for 2 Side by Side columns with flow from top to down and then across

2005-01-21 14:30:42


On Fri, 21 Jan 2005 11:32:49 -0800 (PST), samir sawant <cindy_mona(_at_)yahoo(_dot_)com> wrote:

> Hi I am looking to convert the Large XML file with
> 6 fields into 2 columns.
> Each row has 6 fields.
>
> I want out put in below format:
>
> Row1    Row(n+1)
> Row2    ....
> Row3    ....
> Row4    ....
> ....    ....
> ....    ....
> ....    ....
> Row(n)  Row(2n)

Hi,

Because you not provided a sample XML extract, I will solve the problem for this one:

<the_large_XML>
        
<row><field>1</field><field>2</field><field>3</field><field>4</field><field>5</field><field>6</field></row>
        
<row><field>a1</field><field>a2</field><field>a3</field><field>a4</field><field>a5</field><field>a6</field></row>
        
<row><field>b1</field><field>b2</field><field>b3</field><field>b4</field><field>b5</field><field>b6</field></row>
        
<row><field>c1</field><field>c2</field><field>c3</field><field>c4</field><field>c5</field><field>c6</field></row>
        
<row><field>d1</field><field>d2</field><field>d3</field><field>d4</field><field>d5</field><field>d6</field></row>
        
<row><field>e1</field><field>e2</field><field>e3</field><field>e4</field><field>e5</field><field>e6</field></row>
</the_large_XML>

The following stylesheet:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>

<xsl:output indent="yes"/>

<xsl:param name="columns" select="2"/>
<xsl:variable name="size" select="ceiling(count(the_large_XML/row) div $columns)"/>

<xsl:template match="the_large_XML">
        <table>
                <xsl:apply-templates select="row[position() &lt;= $size]"/>
        </table>
</xsl:template>

<xsl:template match="row">
        <tr>
                <xsl:apply-templates select="." mode="col"/>
        </tr>
</xsl:template>

<xsl:template match="row" mode="col">
        <td>
                <xsl:apply-templates select="*"/>
        </td>
<xsl:apply-templates select="following-sibling::row[position()=$size]" mode="col"/>
</xsl:template>

</xsl:stylesheet>


will result in this output:
<table>
   <tr>
      <td>123456</td>
      <td>c1c2c3c4c5c6</td>
   </tr>
   <tr>
      <td>a1a2a3a4a5a6</td>
      <td>d1d2d3d4d5d6</td>
   </tr>
   <tr>
      <td>b1b2b3b4b5b6</td>
      <td>e1e2e3e4e5e6</td>
   </tr>
</table>


possibly rendered thus by a user agent:
123456          c1c2c3c4c5c6
a1a2a3a4a5a6    d1d2d3d4d5d6
b1b2b3b4b5b6    e1e2e3e4e5e6


This is probably not really what you want, so provide more details of the output you're expecting.


regards,
--
Using Opera's revolutionary e-mail client: http://www.opera.com/m2/


--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--



<Prev in Thread] Current Thread [Next in Thread>