• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Displaying first n rows of XML data

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm new to XSLT and would like to transform the following XML:
_________________________________

<item>
<data>
<tr>
<td>ROW</td>
<td>MANUFACTURER</td>
</tr>
<tr>
<td>1</td>
<td>FERRARI</td>
</tr>
<tr>
<td>2</td>
<td>PORSCHE</td>
</tr>
<tr>
<td>3</td>
<td>LAMBORGHINI</td>
</tr>
<tr>
<td>4</td>
<td>BENTLEY</td>
</tr>
<tr>
<td>5</td>
<td>ASTON MARTIN</td>
</tr>
</data>
</item>
_________________________________

What I would like to display is:

ROW MANUFACTURER
1 FERRARI
2 PORSCHE
3 LAMBORGHINI

So, a parameter would be passed to the XSLT (in this case 3) and the first <tr> element would be displayed (the heading) and all other <tr> elements whose first <td> element value <= 3.

My current XSL displays all the data:
_________________________________

<xsl:template match="/item">
<xsl:apply-templates select="data"/>
</xsl:template>

<xsl:template match="data">
<table>
<xsl:apply-templates select="tr"/>
</table>
</xsl:template>

<xsl:template match="tr">
<tr>
<xsl:apply-templates select="td"/>
</tr>
</xsl:template>

<xsl:template match="td">
<td><xsl:value-of select="."/></td>
</xsl:template>
_________________________________

Can anyone help me?
 
Marshal
Posts: 28177
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Perhaps this will get you started:
[ August 07, 2007: Message edited by: Paul Clapham ]
reply
    Bookmark Topic Watch Topic
  • New Topic