aspose file tools*
The moose likes XML and Related Technologies and the fly likes xsl for xml tags with similar name 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 "xsl for xml tags with similar name" Watch "xsl for xml tags with similar name" New topic
Author

xsl for xml tags with similar name

raj agastya
Greenhorn

Joined: Nov 27, 2001
Posts: 22
Hi,
I have an XML file like the following. I need to write an XSL file which will display the following columns of every tag(<col> under each tag(<row> . How do I do this? My sample XSL is also posted below XML which does not display the xml info in the table. Please help me.
</RowSet>
<data>
<row>
<col>7369</col>
<col>SMITH</col>
<col>CLERK</col>
</row>
<row>
<col>7499</col>
<col>ALLEN</col>
<col>SALESMAN</col>
</row>
<row>
<col>7521</col>
<col>WARD</col>
<col>SALESMAN</col>
</row>
</data>
</RowSet>
XSL:
<?xml version="1.0" ?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:template match="row">
<HTML>
<BODY>
<CENTER>
<TABLE>
<TR>
<TD>
<FONT COLOR="#CC0000" SIZE="+1">
<B>List of Products</B>
</FONT>
</TD>
</TR>
<TR>
<TD>
<xsl:for-each select="/RowSet/data/row">
<xsl:value-of select="col"/>
</xsl:for-each>
</TD>
</TR>
</TABLE>
<BR/>
<FORM ACTION="../jsps/Main.jsp" METHOD="post">
<CENTER>
<INPUT TYPE="SUBMIT" NAME="Back" VALUE="Back To Main Page"/>
</CENTER>
</FORM>
</CENTER>
</BODY>
</HTML>
</xsl:template>
</xsl:stylesheet>
Thank you and regards,
Raj.
Ron Newman
Ranch Hand

Joined: Jun 06, 2002
Posts: 1056
You're matching on "row", but you're also doing a foreach on /RowSet/data/row . Do one or the other, not both.


Ron Newman - SCJP 1.2 (100%, 7 August 2002)
Naren
Greenhorn

Joined: Jul 21, 2003
Posts: 23
Replace the corresponding lines with these:

<xsl:template match="data">
===========================
<xsl:for-each select="row">
============================
That's all. It will work
:roll:


<a href="http://www.mqtips.com" target="_blank" rel="nofollow">MQMessenger</a> - free Java app for MQSeries
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: xsl for xml tags with similar name