I'm new to XSL and learning as I go. I'm currently editing a third party stylesheet for XML created locally, part of which looks like this:\[code\]<?xml version="1.0" encoding="UTF-8"?><?xml-stylesheet type="text/xsl"><c01> <did> <unittitle>Annual Reports</unittitle> <physdesc>19 folders</physdesc> </did> <scopecontent> <p>Annual reports...</p> </scopecontent> <c02> <did> <container type="box">1</container> <container type="folder">1</container> <unittitle>1839-40, 1846 (SPP); 1852 (BPA); 1854 (SPP)</unittitle> </did> </c02> <c02> <did> <container type="folder">2</container> <unittitle>1869, 1872 (BPA); 1873 (IAS)</unittitle> </did> </c02><c01> <did> <unittitle>Bulletins</unittitle> <physdesc>2 folders</physdesc> </did> <scopecontent> <p>Bulletins...</p> </scopecontent> <c02> <did> <container type="box">1</container> <container type="folder">21</container> <unittitle>Bulletins 1945-46</unittitle> </did> </c02> <c02> <did> <container type="box">2</container> <container type="folder">1</container> <unittitle>Bulletins 1946-51</unittitle> </did> </c02></c01>\[/code\]With some XSL that creates a table for the many \[code\]<c01>\[/code\]s, \[code\]<c02>\[/code\]s, etc, that looks partially like this:\[code\]<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"><xslutput method="html" encoding="ISO-8859-1" doctype-public="-//W3C//DTD HTML 4.0 Transitional//EN"/><xsl:template match="c02/did"><tr> <xsl:choose> <xsl:when test="ancestor::c01/descendant::c02/did/container"> <xsl:if test="position()=1"> <th><xsl:value-of select="container[1]/@type"/></th> <th><xsl:value-of select="container[2]/@type"/></th> </xsl:if> </xsl:when> <xsltherwise></xsltherwise> </xsl:choose></tr></xsl:template>\[/code\]A table is created prior to this template in the XSL which creates multiple columns, the first two of which are to have \[code\]<th>\[/code\]s that pull the \[code\]<container type>\[/code\] (usually "Box" and "Folder"). Each \[code\]<container type>\[/code\] should only appear once per \[code\]<c01>\[/code\], which it should pull from the first \[code\]<c02>\[/code\]. Sometimes there are \[code\]<c02>\[/code\]s with only one \[code\]<container type>\[/code\], sometimes \[code\]<c01>\[/code\]s have multiple \[code\]<c02>\[/code\]s with both \[code\]<container type="box">\[/code\] & \[code\]<container type="folder">\[/code\].I've tried many variations of \[code\]position()=1\[/code\] and using \[code\]<xsl:choose>\[/code\]/\[code\]<xsl:when>\[/code\], pretty much everything I can think of. It either always displays a \[code\]<th>\[/code\] for every instance of \[code\]<container type="box">\[/code\] & \[code\]<container type="folder">\[/code\] or displays \[code\]<th>\[/code\]s every time there are two \[code\]<container type>\[/code\]s.Any ideas?