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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

XSL Newbie: XSLT do not display specific item from XML

Status
Not open for further replies.
Jan 30, 2002
44
CA
HI Everyone,

I'm trying not to display one category item from the table, specifically 'News' category. How do I go about coding this in my XSL file. Here is the XML code(partial):
<category catid=&quot;4&quot; selected=&quot;0&quot; name=&quot;News &quot; description=&quot;News related to application development&quot;><subcategory subcatid=&quot;63&quot; selected=&quot;0&quot;><name>News </name><company> </company><isHotLink>1</isHotLink><nDocs>39</nDocs></subcategory></category>

Here is the XSL code:
<xsl:stylesheet version=&quot;1.0&quot;
xmlns:xsl=' <xsl:eek:utput method='html'/>
<xsl:template match=&quot;root&quot;>
<xsl:variable name=&quot;count&quot; select=&quot;1&quot;/>
<table cellspacing=&quot;0&quot; WIDTH=&quot;100%&quot;>



<tr>
<xsl:apply-templates select=&quot;category[1]&quot; />
<xsl:apply-templates select=&quot;category[2]&quot; />
<xsl:apply-templates select=&quot;category[3]&quot; />
</tr>
<tr/><tr/><tr/><tr/><tr/><tr/>

<tr><td width=&quot;25%&quot; valign=&quot;top&quot;>
<xsl:apply-templates select=&quot;category[1]/subcategory&quot; />
</td>

<td width=&quot;5%&quot;></td>
<td width=&quot;25%&quot; valign=&quot;top&quot;>
<xsl:apply-templates select=&quot;category[2]/subcategory&quot; /></td>
<td width=&quot;5%&quot;></td>
<td valign=&quot;top&quot; width=&quot;25%&quot;>
<xsl:apply-templates select=&quot;category[3]/subcategory&quot; /></td>
</tr>
<tr/><tr/><tr/><tr/><tr/><tr/>
<tr>
<xsl:apply-templates select=&quot; category[4]&quot; />
<xsl:apply-templates select=&quot; category[5]&quot; />
<xsl:apply-templates select=&quot; category[6]&quot; />
</tr>

<tr>
<td valign=&quot;top&quot; width=&quot;25%&quot;>
<xsl:apply-templates select=&quot;category[4]/subcategory&quot; /> </td>
<td width=&quot;5%&quot;></td>
<td valign=&quot;top&quot; width=&quot;25%&quot;>
<xsl:apply-templates select=&quot;category[5]/subcategory&quot; />

</td>
<td width=&quot;5%&quot;></td>
<td valign=&quot;top&quot; width=&quot;25%&quot;>
<xsl:apply-templates select=&quot;category[6]/subcategory&quot; /> </td>

</tr>


<tr>
<td colspan=&quot;5&quot; valign=&quot;top&quot; align=&quot;right&quot; >
<br/><br/>
<a>
<xsl:attribute name=&quot;href&quot;>Category.asp?CatID=0</xsl:attribute>
more categories...
</a>
</td>

</tr>


</table>
</xsl:template>

<xsl:template match=&quot;category&quot;>
<a>
<xsl:attribute name=&quot;href&quot;>Category.asp?CatID=<xsl:value-of select=&quot;normalize-space(@catid)&quot;/>&amp;Catname=<xsl:value-of select=&quot;normalize-space(@name)&quot;/></xsl:attribute>
<td width=&quot;25%&quot; class=&quot;Category&quot; bgcolor=&quot;333366&quot; onMouseOut=&quot;this.bgColor='333366';return true;&quot;
onMouseOver=&quot;this.bgColor='FF9900';this.style.cursor='hand';&quot;>
<xsl:attribute name=&quot;title&quot;><xsl:value-of select=&quot;@description&quot; /></xsl:attribute>
<xsl:value-of select=&quot;@name&quot; />

</td>
</a>

<td width=&quot;5%&quot;></td>


</xsl:template>


<xsl:template match=&quot;subcategory&quot;>
<xsl:if test=&quot;(position() &lt; 5)&quot;>
<a>
<xsl:attribute name=&quot;href&quot;>Subcategory.asp?SubCatID=<xsl:value-of select=&quot;normalize-space(@subcatid)&quot;/></xsl:attribute>
<xsl:value-of select=&quot;name&quot; /></a>
<xsl:if test=&quot;(position() &lt; 4)&quot;>
<xsl:if test=&quot;not(position()=last())&quot;>, </xsl:if>
</xsl:if>
</xsl:if>
</xsl:template>



</xsl:stylesheet>

Thanks for all your help!!!
 
I'm not quite sure how your xsl works exactly but to loop through all items except a specific one is generally done like this:


<xsl:for-each select=&quot;//Root/Category[Name!='News']&quot;>

Loop content goes in here

</xsl:for-each>

This would show the loop for all Categories apart from the one where the name was 'News'.

Hope this helps! Nick (Software Developer)


nick@retrographics.fsnet.co.uk
nick.price@myenable.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top