Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

xsl for xml tags with similar name

 
raj agastya
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1056
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're matching on "row", but you're also doing a foreach on /RowSet/data/row . Do one or the other, not both.
 
Naren
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Replace the corresponding lines with these:

<xsl:template match="data">
===========================
<xsl:for-each select="row">
============================
That's all. It will work
:roll:
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic