Chima:
Okay, I'll bite. The trick is that we're doing a straightforward mapping of
one tree to the other, only performing a bit of testing to determine (a)
where to quit, and (b) how to label our output as we go.
This stylesheet--
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" indent="yes" />
<xsl:param name="selection">Topic 2.1.1</xsl:param>
<xsl:template match="menuItem">
<div>
<xsl:apply-templates select="description"/>
<xsl:if test="$selection = descendant::description">
<!-- We keep going if we're open. We're open if $selection
corresponds to our description or that of one of our
descendants -->
<xsl:apply-templates select="menuItem"/>
</xsl:if>
</div>
</xsl:template>
<xsl:template match="description">
<span>
<xsl:choose>
<xsl:when test="$selection = ../descendant::description">
<!-- We use the same test as above to determine our label, except
it's our parent menuItem that we're descending from. -->
<xsl:text>O </xsl:text>
</xsl:when>
<xsl:otherwise>
<!-- otherwise it's closed -->
<xsl:text>C </xsl:text>
</xsl:otherwise>
</xsl:choose>
<xsl:apply-templates/>
<!-- Brian wanted sth different, but we'll just go for the
description element's content to finish our label. -->
</span>
</xsl:template>
</xsl:stylesheet>
run on Brian's source (simplified):
<?xml version="1.0"?>
<menu>
<menuItem id="docid1">
<description>Topic 1</description>
<menuItem id="docid2">
<description>Topic 1.1</description>
</menuItem>
<menuItem id="docid3">
<description>Topic 1.2</description>
</menuItem>
</menuItem>
<menuItem id="docid4">
<description>Topic 2</description>
<menuItem id="docid5">
<description>Topic 2.1</description>
<menuItem id="docid2">
<description>Topic 2.1.1</description>
<menuItem id="docid2">
<description>Topic 2.1.1.1</description>
</menuItem>
<menuItem id="docid3">
<description>Topic 2.1.1.2</description>
</menuItem>
</menuItem>
<menuItem id="docid3">
<description>Topic 2.1.2</description>
<menuItem id="docid2">
<description>Topic 2.1.2.1</description>
</menuItem>
<menuItem id="docid3">
<description>Topic 2.1.2.2</description>
</menuItem>
</menuItem>
</menuItem>
<menuItem id="docid6">
<description>Topic 2.2</description>
</menuItem>
</menuItem>
<menuItem id="docid7">
<description>Topic 3</description>
<menuItem id="docid8">
<description>Topic 3.1</description>
</menuItem>
<menuItem id="docid9">
<description>Topic 3.2</description>
</menuItem>
</menuItem>
</menu>
Gives (defaulting the parameter to "2.1.1"):
<div><span>C Topic 1</span></div>
<div><span>O Topic 2</span>
<div><span>O Topic 2.1</span>
<div><span>O Topic 2.1.1</span>
<div><span>C Topic 2.1.1.1</span></div>
<div><span>C Topic 2.1.1.2</span></div>
</div>
<div><span>C Topic 2.1.2</span></div>
</div>
<div><span>C Topic 2.2</span></div>
</div>
<div><span>C Topic 3</span></div>
Much easier than climbing down and then back up a bunch of times, eh?
Cheers,
Wendell
At 11:04 AM 4/1/2003, you wrote:
I wouldn't mind having a look at the XSL for this. I'm doing something
similar and have been banging my head against a wall.
(At least if you could show me some resources on the net which might be
useful, I'd be most grateful)
ChimaI
======================================================================
Wendell Piez
mailto:wapiez(_at_)mulberrytech(_dot_)com
Mulberry Technologies, Inc. http://www.mulberrytech.com
17 West Jefferson Street Direct Phone: 301/315-9635
Suite 207 Phone: 301/315-9631
Rockville, MD 20850 Fax: 301/315-8285
----------------------------------------------------------------------
Mulberry Technologies: A Consultancy Specializing in SGML and XML
======================================================================
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list