xsl-list
[Top] [All Lists]

Splitting data into smaller groups for HTML output.

2005-10-31 11:34:19
Hello,

I'm fairly new to XSL and despite picking things up quickly I've hit a
problem with a template I'm trying to create.

I have an XML file which is structured like this:

<sources>
    <source>
        <title>Title 1</title>
        <url>http://url1.com/</url>
    </source>
    <source>
        <title>Title 2</title>
        <url>http://url2.com/</url>
    </source>
    <source>
        <title>Title 3</title>
        <url>http://url3.com/</url>
    </source>
    <source>
        <title>Title 4</title>
        <url>http://url3.com/</url>
    </source>
</sources>

...and so on. The XML file is dynamically generated by PHP and there
are usually around 10 - 25 <source> nodes and only ever one <sources>
node.

What I've been trying to do is use a template to output these
<sources> in to an HTML file, but and here's the rub - splitting the
<sources> into two or more groups within the HTML. It'd be easier to
show an example...

<div>
  <a href="http://url1.com/";>Title 1</a><br />
  <a href="http://url2.com/";>Title 2</a><br />
</div>
<div>
  <a href="http://url3.com/";>Title 3</a><br />
  <a href="http://url4.com/";>Title 4</a><br />
</div>

The best I can achieve, using <xsl:for-each> is:

<div>
  <a href="http://url1.com/";>Title 1</a><br />
  <a href="http://url2.com/";>Title 2</a><br />
  <a href="http://url3.com/";>Title 3</a><br />
  <a href="http://url4.com/";>Title 4</a><br />
</div>


Doing something like this is pretty straightforward using PHP, with
counter variables and what-not. I realise that XSL works differently
in this respect and was hoping that someone might have some advice for
me on how I can achieve the desired results.

Thanks in advance!

Mike.

--~------------------------------------------------------------------
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>