By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
464,325 Members | 1,235 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 464,325 IT Pros & Developers. It's quick & easy.

Problem with XSL

P: 2
I'm trying to make a HTML with XSLT from XML code already made. On the page I can't see some information I want like: Item number, gender, size and price. Is suppose to be 15 row all with information. Thanks a lot for the helps ans tips!


The XML Code is:

Expand|Select|Wrap|Line Numbers
  1. <?xml version="1.0"?>
  2. <?xml:stylesheet type = "text/xsl" href = "catalog.xsl"?>
  3. <catalog>
  4.     <product description="Cardigan Sweater" product_image="cardigan.jpg">
  5.         <catalog_item gender="Men's">
  6.             <item_number>QWZ5671</item_number>
  7.             <price>39.95</price>
  8.             <size description="Medium">
  9.                 <color_swatch image="red_cardigan.jpg">Red</color_swatch>
  10.                 <color_swatch image="burgundy_cardigan.jpg">Burgundy</color_swatch>
  11.             </size>
  12.             <size description="Large">
  13.                 <color_swatch image="red_cardigan.jpg">Red</color_swatch>
  14.                 <color_swatch image="burgundy_cardigan.jpg">Burgundy</color_swatch>
  15.             </size>
  16.         </catalog_item>
  17.         <catalog_item gender="Women's">
  18.             <item_number>RRX9856</item_number>
  19.             <price>42.50</price>
  20.             <size description="Small">
  21.                 <color_swatch image="red_cardigan.jpg">Red</color_swatch>
  22.                 <color_swatch image="navy_cardigan.jpg">Navy</color_swatch>
  23.                 <color_swatch image="burgundy_cardigan.jpg">Burgundy</color_swatch>
  24.             </size>
  25.             <size description="Medium">
  26.                 <color_swatch image="red_cardigan.jpg">Red</color_swatch>
  27.                 <color_swatch image="navy_cardigan.jpg">Navy</color_swatch>
  28.                 <color_swatch image="burgundy_cardigan.jpg">Burgundy</color_swatch>
  29.                 <color_swatch image="black_cardigan.jpg">Black</color_swatch>
  30.             </size>
  31.             <size description="Large">
  32.                 <color_swatch image="navy_cardigan.jpg">Navy</color_swatch>
  33.                 <color_swatch image="black_cardigan.jpg">Black</color_swatch>
  34.             </size>
  35.             <size description="Extra Large">
  36.                 <color_swatch image="burgundy_cardigan.jpg">Burgundy</color_swatch>
  37.                 <color_swatch image="black_cardigan.jpg">Black</color_swatch>
  38.             </size>
  39.         </catalog_item>
  40.     </product>
  41. </catalog>
The XSL Code I'm trying to do is:

Expand|Select|Wrap|Line Numbers
  1. <?xml version="1.0"?> <!-- DWXMLSource="catalog.xml" -->
  2. <!-- catalog.xsl - Transformation of information into HTML -->
  3. <!-- <?xml:stylesheet type = "text/xml" href = "catalog.xml"?> -->
  4. <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  5. <xsl:template match="/">
  6.  
  7. <html xmlns="http://www.w3.org/1999/xhtml">
  8.     <xsl:apply-templates/>
  9. </html>
  10. </xsl:template>
  11.  
  12. <xsl:template match = "catalog">
  13.  
  14. <head>
  15. <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"/>
  16. <title>Catalog Sweater</title>
  17. </head>
  18.  
  19. <body bgcolor = "white">
  20. <h2>Description: <xsl:value-of select = "./product/@description"/>, <xsl:value-of select = "./product/@product_image"/></h2>
  21. <table border="1" width="100%" id="table1">
  22.     <tr>
  23.         <th>ITEM NUMBER</th>
  24.         <th>COLOR</th>
  25.         <th>GENDER</th>
  26.         <th>SIZE</th>
  27.         <th>PRICE</th>
  28.     </tr>
  29.     <xsl:for-each select="./product/catalog_item/size/color_swatch">
  30.     <tr>
  31.         <td><xsl:value-of select = "catalog/product/catalog_item/item_number"/></td>    
  32.         <td><xsl:value-of select = "./color_swatch"/> - <xsl:value-of select = "./@image"/></td>
  33.         <td><xsl:value-of select = "catalog/product/catalog_item/@gender"/></td>    
  34.         <td><xsl:value-of select = "./@description"/></td>
  35.         <td>$<xsl:value-of select = "catalog/product/catalog_item/price"/></td>
  36.     </tr>
  37.     </xsl:for-each>
  38. </table>
  39.  
  40.  
  41. </body>
  42.  
  43. </xsl:template>
  44. </xsl:stylesheet>
May 20 '07 #1
Share this Question
Share on Google+
3 Replies

dorinbogdan
Expert 100+
P: 839
update the for-each loop as:
Expand|Select|Wrap|Line Numbers
  1. <td><xsl:value-of select = "../../item_number"/></td>    
  2. <td><xsl:value-of select = "."/> - <xsl:value-of select = "@image"/></td>
  3. <td><xsl:value-of select = "../../@gender"/></td>    
  4. <td><xsl:value-of select = "../@description"/></td>
  5. <td>$<xsl:value-of select = "../../price"/></td>
  6.  
May 21 '07 #2

P: 2
Thanks a lot!!!! How can i create a schema to validate it????
May 22 '07 #3

dorinbogdan
Expert 100+
P: 839
The schema depends on your requirements.
I recommend to take an overview over this short tutorial.

We don't provide full source code (it's against site rules), just suggestions and code snippets.
May 22 '07 #4

Post your reply

Sign in to post your reply or Sign up for a free account.