Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: XML XSLT
hi all.
i m trying to transforming a XML doc into a HTML. and trying to write a XSLT file for this. may i got help in this scenario..
if xml is like:
<catalog>
	<cd>
		<title>Empire Burlesque</title>
		<artist>Bob Dylan</artist>
		<country>USA</country>
		
	</cd>
</catalog>
 
the xslt woulb be like this:
<xsl:template match="/">
  <html>
  <body>
  <h2>My CD Collection</h2>
    <table border="1">
      <tr bgcolor="#9acd32">
        <th>Title</th>
        <th>Artist</th>
      </tr>
      <xsl:for-each select="catalog/cd">
      <tr>
        <td><xsl:value-of select="title"/></td>
        <td><xsl:value-of select="artist"/></td>
      </tr>
      </xsl:for-each>
    </table>
  </body>
  </html>
</xsl:template>
</xsl:stylesheet>
 
but if xml is like this:
<catalog>
	<cd>
		<title name="Empire Burlesqu"/>
		<artist name="Bob Dylan"/>
		<country name="USA"/>
		
	</cd>
</catalog>
 
how would be the XSLT for this.
Posted 13-Dec-12 3:57am

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Try this, it should work
 
<xsl:template match="/">
  <html>
  <body>
  <h2>My CD Collection</h2>
    <table border="1">
      <tr bgcolor="#9acd32">
        <th>Title</th>
        <th>Artist</th>
      </tr>
      <xsl:for-each select="catalog/cd">
      <tr>
        <td><xsl:value-of select="title/@name"/></td>
        <td><xsl:value-of select="artist/@name"/></td>
        <td><xsl:value-of select="country/@name"/></td>
      </tr>
      </xsl:for-each>
    </table>
  </body>
  </html>
</xsl:template>
</xsl:stylesheet>
  Permalink  
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 380
1 OriginalGriff 230
2 DamithSL 220
3 Zoltán Zörgő 150
4 Maciej Los 135
0 OriginalGriff 7,740
1 DamithSL 5,694
2 Sergey Alexandrovich Kryukov 5,404
3 Maciej Los 5,061
4 Kornfeld Eliyahu Peter 4,539


Advertise | Privacy | Mobile
Web01 | 2.8.141223.1 | Last Updated 13 Dec 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100