[xsl] Re: creating mutiple columns

Subject: [xsl] Re: creating mutiple columns
From: Dimitre Novatchev <dnovatchev@xxxxxxxxx>
Date: Fri, 22 Jun 2001 02:58:13 -0700 (PDT)
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

Given the following input:


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="/">
            select="/node/element[position() mod $elementsPerRow = 1]"
  <xsl:template match="element" mode="wrap">
        <td><xsl:value-of select="."/></td>
        <xsl:apply-templates select="following-sibling::element[position() &lt;
  <xsl:template match="element">
        <td><xsl:value-of select="."/></td>

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


Dimitre Novatchev.

Do You Yahoo!?
Get personalized email addresses from Yahoo! Mail

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

Current Thread