[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: creating mutiple columns

Subject: Re: creating mutiple columns
From: Dimitre Novatchev <dnovatchev@xxxxxxxxx>
Date: Fri, 22 Jun 2001 02:58:13 -0700 (PDT)
html input mutiple select
Michael Zehrer wrote:
> 
> I have XML data in the format:
> 
> <node>
> <element>...<element/>
> <element>...<element/>
> <element>...<element/>
> ...
> </node>
> 
> In the HTML output I need to put these <element/> data in multiple columns
> with a maximum of 3 rows per column like this:
> 
> element1 | element4 | element7
> element2 | element5 | ...
> element3 | element6 | ...
> 
> Is there any way to do this in xsl?

Yes, but your sample xml input is not well-formed -- the syntax for end tags is
</someName>.

Given the following input:

<node>
    <element>element1</element>
    <element>element2</element>
    <element>element3</element>
    <element>element4</element>
    <element>element5</element>
    <element>element6</element>
    <element>element7</element>
    <element>element8</element>
    <element>element9</element>
    <element>element10</element>
    <element>element11</element>
</node>

the following stylesheet will transform it to a table having $elementsPerRow
elements per row (columns):

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:output indent="yes" omit-xml-declaration="yes"/>

  <xsl:param name="elementsPerRow" select="3"/>
  <xsl:template match="/">
     <table>
        <xsl:apply-templates
            select="/node/element[position() mod $elementsPerRow = 1]"
            mode="wrap"
        />
     </table>
  </xsl:template>
  <xsl:template match="element" mode="wrap">
      <tr>
        <td><xsl:value-of select="."/></td>
        <xsl:apply-templates select="following-sibling::element[position() &lt;
$elementsPerRow]"/>
      </tr>
  </xsl:template>
  <xsl:template match="element">
        <td><xsl:value-of select="."/></td>
  </xsl:template>
</xsl:stylesheet>


In your case $elementsPerRow is set to 3 and the output is the following:

<table>
<tr>
<td>element1</td>
<td>element2</td>
<td>element3</td>
</tr>
<tr>
<td>element4</td>
<td>element5</td>
<td>element6</td>
</tr>
<tr>
<td>element7</td>
<td>element8</td>
<td>element9</td>
</tr>
<tr>
<td>element10</td>
<td>element11</td>
</tr>
</table>

Cheers,
Dimitre Novatchev.






__________________________________________________
Do You Yahoo!?
Get personalized email addresses from Yahoo! Mail
http://personal.mail.yahoo.com/

 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.