Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Deisplaying XML using XSL

Status
Not open for further replies.

TomWestcott

Programmer
Joined
Dec 11, 2003
Messages
1
Location
GB
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=&quot; version=&quot;1.0&quot;>

<xsl:output method='xhtml'
doctype-public = &quot;-//W3C//DTD XHTML 1.0 Strict//EN&quot;
doctype-system = &quot;/>

<xsl:template match=&quot;/&quot;>


<table class=&quot;catMenu&quot;>


<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=&quot;//category[count(*)&gt;0]&quot; />
</tbody>

</table>


</xsl:template>

<xsl:template match=&quot;category&quot;>
<xsl:if test=&quot;parentID &lt; 1&quot;>
<tr>

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

</tr>
<xsl:for-each select=&quot;category/parentID&quot; = &quot;1&quot;>
<tr>
<td>--<xsl:value-of select=&quot;name&quot;/></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
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top