xsl-list
[Top] [All Lists]

RE: XSL resources - Flat to hierarchy - Common ancestors

2004-07-27 04:48:09
Not wishing to quit on a winning streak...
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">
<xsl:variable name="MenuId" select="@MenuId"/>
      <xsl:apply-templates select="ancestor-or-self::Menu[(_at_)MenuId =
$MenuId]"
mode="MenuId">
              <xsl:with-param name="MenuId" select="$MenuId" />
      </xsl:apply-templates>
</xsl:template>

<xsl:template match="Menu" mode="MenuId">
<xsl:param name="MenuId"/>
... output what you want here ...
<xsl:apply-templates select="*[(_at_)MenuId = $MenuId]" mode="MenuId">
      <xsl:with-param name="MenuId" select="$MenuId"/>
</xsl:apply-templates>
</xsl:template>

Untested, but this is the general idea...
What do the variable and the parameter do?

Wouldn't <xsl:with-param name="MenuId" select="@MenuId" /> also work in
the first "Menu" template ?

I take it this isn't the same as a parameter which would be passed in on
a query string (or whatever the xsl equivalent is)?
What I want to be able to do is to pass a MenuId to the xsl and have it
collapse everything except the branch on which that Menu is (in case
anyone wondered, the target use is for a frameless web site with 400+
menus, where I don't want to display all 400 menus on every click, and
where I don't want to loop through them on every click either)

Is that what this example does?

->If it isn't clear what I mean by 'collapse everything but', I'll send
an example