File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Soft Skills: The software developer's life manual this week in the Jobs Discussion forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Displaying first n rows of XML data

 
Ravi Mann
Greenhorn
Posts: 8
  • 0
  • Mark post as helpful
  • send pies
  • 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?
 
Paul Clapham
Sheriff
Pie
Posts: 20153
23
MySQL Database
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Perhaps this will get you started:
[ August 07, 2007: Message edited by: Paul Clapham ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic