MaKSiNG
Technical User
- Dec 4, 2003
- 19
Hi XMLers,
I presume there must a really simple way of doing what I am trying to achieve but I am having some trouble getting my head around it.
My XML is the following:
<record>
<item name="r_news">
<value>
<item name="news_title">
<value>Here is the News Title</value>
</item>
<item name="news_desc">
<value>Here is the News</value>
</item>
</value>
<value>
<item name="news_title">
<value>Here is the 2nd News Title</value>
</item>
<item name="news_desc">
<value>Here is the 2nd News</value>
</item>
</value>
<value>
<item name="news_title">
<value>Here is the 3rd News Title</value>
</item>
<item name="news_desc">
<value>Here is the 3rd News</value>
</item>
</value>
<value>
<item name="news_title">
<value>Here is the News 4th Title</value>
</item>
<item name="news_desc">
<value>Here is the 4th News</value>
</item>
</value>
<value>
<item name="news_title">
<value>Here is the 5th News Title</value>
</item>
<item name="news_desc">
<value>Here is the 5th News</value>
</item>
</value>
</item>
</record>
I have no issue creating a table and displaying the content in a list. One under the other.
However, I need to display these in a table with 2 columns, so that I get:
News 2nd News
3rd News 4th News
5th News
In HTML that is easy by defining a new <TD> for each news item and then calling a new <TR> after the 2nd News and the 4th News.
But using the <for-each> statement to iterate through the content I am not sure how to force a <TR> after every second news item as opposed to every single news item because obviously it places the <TR> after each iteration.
Here is the XSL I have already. Does anybody know a simple way to change this for my needs:
<table width="100%">
<xsl:for-each select="record/item[@name='r_news']/value">
<tr>
<td>
<table width="48%">
<tr>
<td>
<xsl:value-of select="item[@name='news_title']/value" />
</td>
</tr>
<tr>
<td>
<xsl:value-of select="item[@name='news_desc']/value" />
</td>
</tr>
</table>
</td>
</tr>
</xsl:for-each>
</table>
I guess I need another <for-each> statement somewhere or move the one I have but where? Help!
Thx,
MaKS
I presume there must a really simple way of doing what I am trying to achieve but I am having some trouble getting my head around it.
My XML is the following:
<record>
<item name="r_news">
<value>
<item name="news_title">
<value>Here is the News Title</value>
</item>
<item name="news_desc">
<value>Here is the News</value>
</item>
</value>
<value>
<item name="news_title">
<value>Here is the 2nd News Title</value>
</item>
<item name="news_desc">
<value>Here is the 2nd News</value>
</item>
</value>
<value>
<item name="news_title">
<value>Here is the 3rd News Title</value>
</item>
<item name="news_desc">
<value>Here is the 3rd News</value>
</item>
</value>
<value>
<item name="news_title">
<value>Here is the News 4th Title</value>
</item>
<item name="news_desc">
<value>Here is the 4th News</value>
</item>
</value>
<value>
<item name="news_title">
<value>Here is the 5th News Title</value>
</item>
<item name="news_desc">
<value>Here is the 5th News</value>
</item>
</value>
</item>
</record>
I have no issue creating a table and displaying the content in a list. One under the other.
However, I need to display these in a table with 2 columns, so that I get:
News 2nd News
3rd News 4th News
5th News
In HTML that is easy by defining a new <TD> for each news item and then calling a new <TR> after the 2nd News and the 4th News.
But using the <for-each> statement to iterate through the content I am not sure how to force a <TR> after every second news item as opposed to every single news item because obviously it places the <TR> after each iteration.
Here is the XSL I have already. Does anybody know a simple way to change this for my needs:
<table width="100%">
<xsl:for-each select="record/item[@name='r_news']/value">
<tr>
<td>
<table width="48%">
<tr>
<td>
<xsl:value-of select="item[@name='news_title']/value" />
</td>
</tr>
<tr>
<td>
<xsl:value-of select="item[@name='news_desc']/value" />
</td>
</tr>
</table>
</td>
</tr>
</xsl:for-each>
</table>
I guess I need another <for-each> statement somewhere or move the one I have but where? Help!
Thx,
MaKS