XML Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming Languages - MoreXML Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old April 12th, 2012, 05:37 PM
kamil234 kamil234 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2011
Posts: 6 kamil234 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 54 m 50 sec
Reputation 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>

Reply With Quote
  #2  
Old April 12th, 2012, 07:08 PM
kamil234 kamil234 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2011
Posts: 6 kamil234 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 54 m 50 sec
Reputation 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>

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreXML Programming > XML sorting/positioning

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap