<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:aplaws="http://www.aplaws.org.uk/categoryList" xmlns:esd="http://www.esd.org.uk/standards">
	<xsl:namespace-alias stylesheet-prefix="esd" result-prefix="aplaws"/>
	<xsl:template match="esd:ControlledList">
		<categoryList xmlns:aplaws="http://www.aplaws.org.uk/categoryList">
			<xsl:apply-templates select="//esd:Item[(count(esd:BroaderItem) = 0) and (count(esd:UseItem) = 0)]">
				<xsl:with-param name="Level" select="1"/>
			</xsl:apply-templates>
		</categoryList>
	</xsl:template>
	<xsl:template match="esd:Item">
		<xsl:param name="Level"/>
		<xsl:variable name="CurrentId" select="@Id"/>
		<xsl:element name="aplaws:L{$Level}">
			<aplaws:category>
				<xsl:value-of select="esd:Name"/>
			</aplaws:category>
			<xsl:apply-templates select="//esd:Item[esd:BroaderItem/@Id = $CurrentId]">
				<xsl:with-param name="Level" select="number($Level) + 1"/>
			</xsl:apply-templates>
		</xsl:element>
	</xsl:template>
</xsl:stylesheet>
