#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2011
    Posts
    6
    Rep Power
    0

    XML sorting/positioning


    Hello im working on a simple XML website and i have a issue with positioning an element. The page im having trouble with is the product page, basically I want to display a product picture, title, and a table which has product specs inside it, one product after another. For some reason right now when i display it, i have the picture and name of the product for all products, then the table for all products, not one after another.

    HERES MY XSLT CODE
    Code:
    <?xml version="1.0" encoding="utf-8"?><!-- DWXMLSource="product_page.xml" -->
    
    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    
    <xsl:template match="/">
    
    <html>
    <head>
    <title>Kamil's GPS Shop</title>
    <link href="product_page.css" rel="stylesheet" type="text/css" />
    </head>
    
    <body>
    <div class="topbar">
    <a href="homepage.xml"><img class="logo" src="GPS_Logo.png"/></a></div>
    <div class="sidebar">
    <xsl:apply-templates select="page/nav_bar" />
    </div>
    <div class="rightbar"></div>
    <div class="content">
    <h1> Products </h1>
    <xsl:apply-templates select="page/products">
    <xsl:sort select="@id"/>
    </xsl:apply-templates>
    </div>
    </body>
    </html>
    
    </xsl:template>
    
    <xsl:template match="nav_bar">
    <ul>
    <td>
    <a href="homepage.xml"><xsl:value-of select="nav_home"/></a>
    </td>
    </ul>
    <ul>
    <td>
    <a href="product_page.xml"><xsl:value-of select="nav_pro"/></a>
    </td>
    </ul>
    <ul>
    <td>
    <a href="about_page.xml"><xsl:value-of select="nav_about"/></a>
    </td>
    </ul>
    </xsl:template>
    
    
    <xsl:template match="products">
        <div>
        <xsl:for-each select="product">
        <div><img src="{@id}.jpg"/><xsl:value-of select="Specs/name"/></div>
        </xsl:for-each>
    <xsl:apply-templates select="product/Specs"/>
     </div>
    </xsl:template>
    
    
    <xsl:template match="Specs">
     <table border="2" width="850px">
     <tr>
      <th>Brand:</th>
      <th>Model:</th>
      <th>Screen Size:</th>
      <th>Weight:</th>
      <th>Talk to Speech:</th>
      <th>Memory Type:</th>
      <th>Battery Life:</th>
      </tr>
      <tr>
        <xsl:apply-templates select="brand" />
        <xsl:apply-templates select="model" />
        <xsl:apply-templates select="screen_size" />
        <xsl:apply-templates select="weight" />
        <xsl:apply-templates select="TTS" />
        <xsl:apply-templates select="mem_type" />
        <xsl:apply-templates select="battery_life" />
      </tr>
      </table>
     </xsl:template>
    
    
    <xsl:template match="brand|model|screen_size|weight|TTS|mem_type|battery_life">
      <td><xsl:value-of select="." /></td>
    </xsl:template>
    </xsl:stylesheet>
    HERE'S MY XML CODE
    Code:
    <?xml version="1.0" encoding="utf-8" standalone="no" ?>
    
    <?xml-stylesheet type="text/xsl" href="product_page.xsl"?>
    
    
    <page>
    
    <nav_bar>
    	<nav_home> Home </nav_home> 
    	<nav_pro> Products </nav_pro>
    	<nav_about>About Us</nav_about>
    </nav_bar>
    
    
    <products>
    
    <product id="nuvi_50">
    <Specs>
    	<name> Garmin Nuvi 50 5.0" GPS Navigation</name>
    	<brand>Garmin</brand>
    	<model>Nuvi 50</model>
    	<screen_size> 5.0 inches</screen_size>
    	<weight> 6.3 oz</weight>
    	<TTS>Yes </TTS>
    	<mem_type> Micro-SD</mem_type>
    	<battery_life> Up to 2 hours</battery_life>
    </Specs>
    <price><bold>Price:</bold> 139.99</price>
    </product>
    
    
    
    <product id="m_road">
    <Specs>
    	<name>TomTom VIA 1505TM 5.0" GPS Navigation</name>
    	<brand>TomTom</brand>
    	<model>VIA 1505TM</model>
    	<screen_size>5.0 inches</screen_size>
    	<weight>6.46 oz</weight>
    	<TTS>Yes</TTS>
    	<mem_type>Built in</mem_type>
    	<battery_life>Up to 2 hours</battery_life>
    </Specs>
    
    <price><bold>Price:</bold>199.95</price>
    </product>
    
    <product id="tom_1505">
    <Specs>
    	<name>Magellan RoadMate 1424 4.3" GPS Navigation</name>
    	<brand>Magellan</brand>
    	<model>RoadMate 1424</model>
    	<screen_size>4.3 inches</screen_size>
    	<weight>5.5 oz</weight>
    	<TTS>Yes </TTS>
    	<mem_type>N/A</mem_type>
    	<battery_life>Up to 2 hours</battery_life>
    </Specs>
    
    <price><bold>Price: </bold>97.95</price>
    </product>
    
    </products>
    
    
    </page>
  2. #2
  3. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2011
    Posts
    6
    Rep Power
    0
    solved, instead of doing
    Code:
    <xsl:template match="products">
        <div>
        <xsl:for-each select="product">
        <div><img src="{@id}.jpg"/><xsl:value-of select="Specs/name"/></div>
        </xsl:for-each>
    <xsl:apply-templates select="product/Specs"/>
     </div>
    </xsl:template>
    i put all the templates inside the for each statement using the following

    Code:
    <xsl:template match="products">
        <xsl:for-each select="product">
        <div class="product_container"><img src="{@id}.jpg" class="product_img" /><br></br><p class="name"><xsl:value-of select="name" /></p>
        <p><xsl:apply-templates select="." /></p>
         </div>
        </xsl:for-each>

IMN logo majestic logo threadwatch logo seochat tools logo