|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
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"> <xsl utput 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 |
|
#2
|
|||
|
|||
|
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. |
|
#3
|
|||
|
|||
|
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 ! |
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > XML Programming > XSL Help |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|