Documentation Center

Filtering a taxonomy

The Taxonomy API provides a number of filters to change which parts of the taxonomy to display.

You can apply a combination of the following filters to display only a part of a taxonomy:

FilterDescription
DepthFiltertakes an integer depth level and filter direction parameter indicating levels to display, and direction FilterDown and FilterUp or UnlimitedDepth.
AbstractKeywordFilterfilters Keywords on the isAbstract property and takes two Boolean parameters to filter concrete Keywords and filter Abstract.
KeywordPropertyFiltertakes Boolean parameters to filter Keywords on the hasChildren or isNavigable property.
CompositeFilterlets you to combine all of the above filters.
ASP.NET
To apply filtering in ASP.NET you must add the filter settings in the code behind because the filter cannot be passed in the ASPX code. The following code is an example of a standard .aspx page:
<%@ Page Language="C#" AutoEventWireup="true" Debug="true" 
	CodeFile="ShowTaxonomy.aspx.cs" Inherits="ShowTaxonomyProperties" %>
<%@ Import Namespace="Tridion.ContentDelivery.Taxonomies"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
	<head runat="server">
		<title>Taxonomy Control Basic Properties Test</title>
	</head>
	<body>
		<form id="form1" runat="server">
			<tridion:TaxonomyControl ID="taxBasicProperties" 
				TaxonomyURI="tcm:94-535-512" runat="server">
			</tridion:TaxonomyControl>
		</form>
	</body>
</html>

The following code behind example demonstrates how to combine filters by creating a composite filter and adding filters to it:

using System; using Tridion.ContentDelivery.Taxonomies;

public partial class ShowTaxonomyProperties : System.Web.UI.Page
{
	protected void Page_Load(object sender, EventArgs e) {

		CompositeFilter compositeFilter = new CompositeFilter();
		compositeFilter.DepthFiltering(2, DepthFilter.FilterDown);
		compositeFilter.AbstractKeywordFiltering(true, false);
		compositeFilter.PropertyKeywordFiltering(false, false);
		taxBasicProperties.TaxonomyFilter = compositeFilter;
	}
}
Java
The following code example demonstrates how to combine filters by creating a composite filter and adding filters to it:
<%@ page language="java" contentType="text/html"%>
<%@page import="com.tridion.taxonomies.*,
com.tridion.taxonomies.filters.*"%>

<%@ taglib uri="http://www.sdl.com/delivery/tags/cd/2.0" prefix="tridion" %>

<% 
	CompositeFilter myCompositeFilter = new CompositeFilter();//create a new composite filter to hold filters
	myCompositeFilter.depthFiltering(2, DepthFilter.FilterDown);//add depth filter to composite filter
	myCompositeFilter.abstractKeywordFiltering(true, false);//
	myCompositeFilter.keywordPropertyFiltering(true, true);// 
%>
<html>	
	<head><title>Taxonomy Control Test</title></head>
	<body>   
		<form>
			<tridion:TaxonomyControl taxonomyURI="tcm:94-535-512" taxonomyFilter="<%=myCompositeFilter%>"/>            
		</form>
	</body>
</html>
The following code example shows how to create a single depth filter to show only the first two levels of the taxonomy and use it in a tag library:
<%
	DepthFilter depthFilter = new DepthFilter(2, DepthFilter.FilterDown); 
%>
<tridion:TaxonomyControl taxonomyURI="tcm:1-1-512" taxonomyFilter="<%= depthFilter %>" />