Subject: Re: [xsl] XSL resources - Flat to hierarchy - Common ancestors From: "M. David Peterson" <m.david@xxxxxxxxxx> Date: Mon, 26 Jul 2004 10:06:16 -0600 |
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)
<xsl:template match="/Menus"> <xsl:apply-templates select="Menu"/> </xsl:template>
<xsl:template match="Menu" mode="MenuId"> <xsl:param name="MenuId"/> ... output what you want here ... <xsl:apply-templates select="*[@MenuId = $MenuId]" mode="MenuId"> <xsl:with-param name="MenuId" select="$MenuId"/> </xsl:apply-templates> </xsl:template>
<M:D/> :: Saxon.NET general public early beta will be available Tuesday, July 27th :: :: DISCLAIMER: All efforts have been made to ensure a quality beta release :: :: None-the-less, this is an early beta release that should only be used :: :: in test environments for the purpose of testing performance and helping :: :: to locate potential bugs and performance bottlenecks. With this in mind :: :: PLEASE DO NOT CONSIDER THIS RELEASE READY FOR PRODUCTION IMPLEMENTATION! ::
Many thanks for any answers received
Ben Simkins
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
[xsl] XSL resources - Flat to hiera, Ben Simkins | Thread | RE: [xsl] XSL resources - Flat to h, Ben Simkins |
Re: [xsl] DOCTYPE causes appearance, Colin Paul Adams | Date | RE: [xsl] hard xsl problem, Sal Mangano |
Month |