Problem with XSL

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • borikangel
    New Member
    • May 2007
    • 2

    Problem with XSL

    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:

    [code=xml]<?xml version="1.0"?>
    <?xml:styleshee t type = "text/xsl" href = "catalog.xs l"?>
    <catalog>
    <product description="Ca rdigan Sweater" product_image=" cardigan.jpg">
    <catalog_item gender="Men's">
    <item_number>QW Z5671</item_number>
    <price>39.95</price>
    <size description="Me dium">
    <color_swatch image="red_card igan.jpg">Red</color_swatch>
    <color_swatch image="burgundy _cardigan.jpg"> Burgundy</color_swatch>
    </size>
    <size description="La rge">
    <color_swatch image="red_card igan.jpg">Red</color_swatch>
    <color_swatch image="burgundy _cardigan.jpg"> Burgundy</color_swatch>
    </size>
    </catalog_item>
    <catalog_item gender="Women's ">
    <item_number>RR X9856</item_number>
    <price>42.50</price>
    <size description="Sm all">
    <color_swatch image="red_card igan.jpg">Red</color_swatch>
    <color_swatch image="navy_car digan.jpg">Navy </color_swatch>
    <color_swatch image="burgundy _cardigan.jpg"> Burgundy</color_swatch>
    </size>
    <size description="Me dium">
    <color_swatch image="red_card igan.jpg">Red</color_swatch>
    <color_swatch image="navy_car digan.jpg">Navy </color_swatch>
    <color_swatch image="burgundy _cardigan.jpg"> Burgundy</color_swatch>
    <color_swatch image="black_ca rdigan.jpg">Bla ck</color_swatch>
    </size>
    <size description="La rge">
    <color_swatch image="navy_car digan.jpg">Navy </color_swatch>
    <color_swatch image="black_ca rdigan.jpg">Bla ck</color_swatch>
    </size>
    <size description="Ex tra Large">
    <color_swatch image="burgundy _cardigan.jpg"> Burgundy</color_swatch>
    <color_swatch image="black_ca rdigan.jpg">Bla ck</color_swatch>
    </size>
    </catalog_item>
    </product>
    </catalog>[/code]

    The XSL Code I'm trying to do is:

    [code=xml]<?xml version="1.0"?> <!-- DWXMLSource="ca talog.xml" -->
    <!-- catalog.xsl - Transformation of information into HTML -->
    <!-- <?xml:styleshee t type = "text/xml" href = "catalog.xm l"?> -->
    <xsl:styleshe et version="1.0" xmlns:xsl="http ://www.w3.org/1999/XSL/Transform">
    <xsl:template match="/">

    <html xmlns="http://www.w3.org/1999/xhtml">
    <xsl:apply-templates/>
    </html>
    </xsl:template>

    <xsl:template match = "catalog">

    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"/>
    <title>Catalo g Sweater</title>
    </head>

    <body bgcolor = "white">
    <h2>Description : <xsl:value-of select = "./product/@description"/>, <xsl:value-of select = "./product/@product_image"/></h2>
    <table border="1" width="100%" id="table1">
    <tr>
    <th>ITEM NUMBER</th>
    <th>COLOR</th>
    <th>GENDER</th>
    <th>SIZE</th>
    <th>PRICE</th>
    </tr>
    <xsl:for-each select="./product/catalog_item/size/color_swatch">
    <tr>
    <td><xsl:valu e-of select = "catalog/product/catalog_item/item_number"/></td>
    <td><xsl:valu e-of select = "./color_swatch"/> - <xsl:value-of select = "./@image"/></td>
    <td><xsl:valu e-of select = "catalog/product/catalog_item/@gender"/></td>
    <td><xsl:valu e-of select = "./@description"/></td>
    <td>$<xsl:val ue-of select = "catalog/product/catalog_item/price"/></td>
    </tr>
    </xsl:for-each>
    </table>


    </body>

    </xsl:template>
    </xsl:stylesheet>[/code]
  • dorinbogdan
    Recognized Expert Contributor
    • Feb 2007
    • 839

    #2
    update the for-each loop as:
    [code=xml]
    <td><xsl:valu e-of select = "../../item_number"/></td>
    <td><xsl:valu e-of select = "."/> - <xsl:value-of select = "@image"/></td>
    <td><xsl:valu e-of select = "../../@gender"/></td>
    <td><xsl:valu e-of select = "../@description"/></td>
    <td>$<xsl:val ue-of select = "../../price"/></td>
    [/code]

    Comment

    • borikangel
      New Member
      • May 2007
      • 2

      #3
      Thanks a lot!!!! How can i create a schema to validate it????

      Comment

      • dorinbogdan
        Recognized Expert Contributor
        • Feb 2007
        • 839

        #4
        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.

        Comment

        Working...