[xsl] XSL resources - Flat to hierarchy - Common ancestors

Subject: [xsl] XSL resources - Flat to hierarchy - Common ancestors
From: "Ben Simkins" <bsimkins@xxxxxxxxxx>
Date: Mon, 26 Jul 2004 16:55:38 +0200
Three questions in one mail:
1. Does anyone know of a public 'knowledgebase' type site where there
are lots of examples of solutions to different problems, classified in a
way which avoids spending hours trawling through threads?

2. Transforming 'flat' structures to hierarchies:
I've adapted a stylesheet found in this list, for creating the hierarchy
of this:
<Menus>
  <Menu MenuId="58" MenuName="LeftMenu"/>
  <Menu MenuId="1" MenuParentId="58" MenuName="Home"/>
  <Menu MenuId="60" MenuParentId="1" MenuName="About us/>
  ...etc
</Menus>

The xsl looks like this:
<xsl:template match="/">
	<xsl:apply-templates select="Menus"/>
</xsl:template>

<xsl:template match="Menus">
  <xsl:copy>
    <xsl:apply-templates select="Menu[not(@MenuParentId)]">
    </xsl:apply-templates>
  </xsl:copy>
</xsl:template>

<xsl:template match="Menu">
  <xsl:copy>
  	<xsl:copy-of select="@*"/>
  	<xsl:apply-templates select="../Menu[@MenuParentId =
current()/@MenuId]"/>
  </xsl:copy>
</xsl:template>

Question: is there any way of also adding the numbering (<xsl:number
level="multiple" format="1.1"/>) directly, or do I have to run the
output through a second stylesheet?

3. Given the hierarchical output from 2, I would like to extract all
nodes which are children of any of the ancestors of the node with a
given MenuId (including that node itself)
Expressed otherwise: the children, siblings, ancestors, uncles and
great-uncles, great-great-uncles (etc) of the given node.
Expressed otherwise: all Menus where MenuParentId IN (MenuIds of a given
node and all of its ancestors)

Many thanks for any answers received

Ben Simkins

Current Thread