Re: [xsl] even and odds
by =?iso-8859-1?Q?J=F6rg_Heinicke?= other posts by this author
Dec 22 2001 2:29AM messages near this date
Re: [xsl] silbings
|
Re: [xsl] even and odds
Hi Yan,
an example:
<nodes>
<node> 1</node>
<node> 2</node>
<node> 3</node>
<node> 4</node>
<node> 5</node>
<node> 6</node>
</nodes>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/nodes">
<table>
<xsl:apply-templates select="node[position() mod 2 = 1]"/>
</table>
</xsl:template>
<xsl:template match="node">
<tr>
<td> <xsl:value-of select="."/></td>
<td> <xsl:value-of select="preceding-sibling::node[1]"/></td>
</tr>
</xsl:template>
</xsl:stylesheet>
You match only on every second node, so you know where to close and open
<tr> . And while processing these nodes you select their value and the value
of the next one.
Regards,
Joerg
> hey all,
> I have a quick problem.
>
> I have n number of nodes, I want to put those nodes as html.
> I need to take a pair at a time, and display them in a table,
something like:
>
> <tr><td>node1</td><td>node2</td></tr>
>
> the problem is, when I put <tr> tag in there, I can only
> put tr in front of the odd ones, and </tr> to the end of the even
ones.
>
> Now, I can check even/odd using postion() mode etc, but now it
complains
>
> <td> has no end tag, must be due to the conditional statement, how do
I fix
>
> this?
>
> thanks
>
> yan
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
Thread:
Dimitre Novatchev
Yan Zhu
Michael Kay
Yan Zhu
Oleg Tkachenko
Yan Zhu
Michael Kay
Yan Zhu
=?iso-8859-1?Q?J=F6rg_Heinicke?=
Yan Zhu
Gunther Schadow
Dimitre Novatchev
Gunther Schadow
Dimitre Novatchev
Dimitre Novatchev
Gunther Schadow
Yan Zhu
|