XML Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
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 December 11th, 2003, 03:39 PM
TomWestcott TomWestcott is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2003
Location: England
Posts: 19 TomWestcott User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 27 m 13 sec
Reputation Power: 0
Send a message via ICQ to TomWestcott Send a message via AIM to TomWestcott
XSL Help

I am trying to print a list of categorys with sub caegorys is they exsist like this

Category
--subcategory1
Category2

This the xml file and xsl file


<table>
<category>
<title>Category1</title>
<parentID>0</parentID>
<categoryID>1</categoryID>
</category>

<category>
<title>Category2</title>
<parentID>0</parentID>
<categoryID>2</categoryID>
</category>

<category>
<title>SubCategory1</title>
<parentID>1</parentID>
<categoryID>3</categoryID>
</category>
</table>


<?xml version='1.0'?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">

<xslutput method='xhtml'
doctype-public = "-//W3C//DTD XHTML 1.0 Strict//EN"
doctype-system = "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"
/>

<xsl:template match="/">


<table class="catMenu">


<thead>
<tr>
<!-- set up the column headings -->
<th>Category</th>
</tr>
</thead>

<tbody>
<!-- add a table row for each non-empty inner record in the XML file -->
<xsl:apply-templates select="//category[count(*)>0]" />
</tbody>

</table>


</xsl:template>

<xsl:template match="category">
<xsl:if test="parentID < 1">
<tr>

<td><a><xsl:attribute name="href">browse.php?catID=<xsl:value-of select="categoryID"/></xsl:attribute><xsl:value-of select="title"/></a></td>

</tr>
<xsl:for-each select="category/parentID" = "1">
<tr>
<td>--<xsl:value-of select="name"/></td>
</tr>
</xsl:for-each>
</xsl:if>
</xsl:template>
</xsl:stylesheet>

As you can see I need help at the for each bit im a newb!

Thank Tom

Reply With Quote
  #2  
Old December 11th, 2003, 05:22 PM
tsprings tsprings is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2003
Location: Seattle, WA
Posts: 55 tsprings User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 5 m 20 sec
Reputation Power: 6
Hello Tom. I'm not exactly sure what you're trying to do here. Perhaps you could be a tad more specific? I read your xsl, and it looked as though you wanted to select parentID's less than 1, but then in that IF statement you want the parentID's equal to 1 (of course that's never going to happen). I tweaked your code a tad to get it to display something that I thought you were looking for, but I'm not sure if this is correct since I'm hazy on what exactly you're trying to do.

I changed your xml file as you can put change the ID elements to attributes (these make more sense as attributes) - I would have changed the rest of the xml if necessary but again, I don't know what you're trying to accomplish.

table.xml
Code:
<?xml version="1.0" ?>
<?xml-stylesheet type="text/xsl" href="table.xsl" ?>
<table>
  <category categoryID="1" parentID="0">
    <title>Category1</title>
   </category>

   <category categoryID="2" parentID="0">
    <title>Category2</title>
   </category>

   <category categoryID="3" parentID="1">
    <title>SubCategory1</title>
   </category>
</table>


table.xsl
Code:
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
  <body>
     <table class="catMenu" border="1">
       <thead>
         <tr>
           <!-- set up the column headings -->
           <th>Category</th>
         </tr>
       </thead>
       <tbody>
         <!-- add a table row for each non-empty inner record in the XML file -->
         <xsl:apply-templates select="//category[count(*)>0]" />
       </tbody>
     </table>
   </body>
</html>
</xsl:template>

<xsl:template match="category">
   <xsl:if test="@parentID < 1">
     <tr>
       <td><a href="browse.php?catID={@categoryID}"><xsl:value-of select="title"/></a></td>
     </tr>    
   </xsl:if>     
   <xsl:if test="@parentID = 1">
       <tr>
         <td>--<xsl:value-of select="title"/></td>
       </tr>
   </xsl:if>
</xsl:template>

</xsl:stylesheet>

Take a look at what kind of output you get from the revamped xsl, and let me know exactly what you're looking for and I'll try to offer more help.

Reply With Quote
  #3  
Old December 11th, 2003, 06:15 PM
TomWestcott TomWestcott is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2003
Location: England
Posts: 19 TomWestcott User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 27 m 13 sec
Reputation Power: 0
Send a message via ICQ to TomWestcott Send a message via AIM to TomWestcott
Sorta i wil ltry to explain more

<?xml version="1.0" ?>
<?xml-stylesheet type="text/xsl" href="table.xsl" ?>
<table>
<category categoryID="1" parentID="0">
<title>Category1</title>
</category>

<category categoryID="2" parentID="0">
<title>Category2</title>
</category>

<category categoryID="3" parentID="1">
<title>SubCategory for cat 1</title>
</category>

<category categoryID="3" parentID="2">
<title>SubCategory for cat 2</title>
</category>
</table>

Ok the parent ID refers to the parent category id so in subcategory for cat 1 the parent id is 1 refering to Category 1 so this would like to produce

Category1
-- SubCategory for cat 1

Category2
-- SubCategory for cat 2

does this help thanks very much for your help !

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreXML Programming > XSL Help


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 | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway
Stay green...Green IT