File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes XML and Related Technologies and the fly likes Displaying first n rows of XML data Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "Displaying first n rows of XML data" Watch "Displaying first n rows of XML data" New topic
Author

Displaying first n rows of XML data

Ravi Mann
Greenhorn

Joined: Jun 29, 2001
Posts: 8
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
Bartender

Joined: Oct 14, 2005
Posts: 18570
    
    8

Perhaps this will get you started:
[ August 07, 2007: Message edited by: Paul Clapham ]
 
GeeCON Prague 2014
 
subject: Displaying first n rows of XML data