Subject: Re: [xsl] Splitting data into smaller groups for HTML output. From: Wendell Piez <wapiez@xxxxxxxxxxxxxxxx> Date: Mon, 31 Oct 2005 13:34:42 -0500 |
<xsl:template match="sources"> <div> <xsl:apply-templates select="source[position() <= (last() div 2)"/> </div> <div> <xsl:apply-templates select="source[position() > (last() div 2)"/> </div> </xsl:template>
Cheers, Wendell
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.
====================================================================== Wendell Piez mailto:wapiez@xxxxxxxxxxxxxxxx Mulberry Technologies, Inc. http://www.mulberrytech.com 17 West Jefferson Street Direct Phone: 301/315-9635 Suite 207 Phone: 301/315-9631 Rockville, MD 20850 Fax: 301/315-8285 ---------------------------------------------------------------------- Mulberry Technologies: A Consultancy Specializing in SGML and XML ======================================================================
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
[xsl] Splitting data into smaller g, Mike Rumble | Thread | Re: [xsl] Splitting data into small, Mike Rumble |
[xsl] Splitting data into smaller g, Mike Rumble | Date | Re: [xsl] XSLT 2.0 : Deployment, Frans Englich |
Month |