[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

RE: XSL resources - Flat to hierarchy - Common ancesto

Subject: RE: XSL resources - Flat to hierarchy - Common ancestors
From: "Ben Simkins" <bsimkins@xxxxxxxxxx>
Date: Tue, 27 Jul 2004 17:20:41 +0200
xsl menu
*3. Common ancestors*

Well, your warning about not knowing it all was pretty apt

1. I can't understand how xsl:variable can be static, seems like a
contradiction?

2. I couldn't get my head round your example, and I've been trying
different solutions without much success, but I figure what I need now
is understanding more than code. So here goes for a few questions.

My idea to solve this one was,
Given that I will pass in the MenuId, I create a global param:
<xsl:param name="MenuId" select="'198'"/>

a). I copy the root and get the Menu that corresponds to my MenuId:
<xsl:template match="/Menus">
	<xsl:element name="Menus">
		<xsl:apply-templates select="//Menu[@MenuId = $MenuId]"
mode="ABC"/>
	</xsl:element">
</xsl:template>

b). I get the node set of ancestors-or-self of this menu:
<xsl:template match="Menu" mode="ABC">
	<xsl:apply-templates select="ancestor-or-self::Menu"
mode="DEF"/>
</xsl:template>

c). I copy each of these menus, and any of its children (but not
grandchildren):
<xsl:template match="Menu" mode="DEF">
    <xsl:copy>
      <xsl:copy-of select="@* | child::Menu"/>
    </xsl:copy>
</xsl:template>

But there's still something not right.
1) do the nodes returned by ancestor-or-self retain their hierarchy?
2) when I do an apply templates on ancestor-or-self, do they 'remember'
the rest of the document, ie. Can the called template access their
children etc.?
3) Why do I need the ::Menu?
4) Why does child::Menu seem to return all the descendants and not just
the first generation?

Here's some data to test on:
<Menus>
  <Menu MenuId="23">
    <Menu MenuId="42"/>
    <Menu MenuId="84">
      <Menu MenuId="198">
        <Menu MenuId="53"/>
      </Menu>
      <Menu MenuId="23">
        <Menu MenuId="84"/>
      </Menu>
    </Menu>
    <Menu MenuId="65"/>
  </Menu>
  <Menu MenuId="47">
    <Menu MenuId="85">
      <Menu MenuId="79"/>
    </Menu>
  </Menu>
</Menus>

The expected result set should be:
<Menus>
  <Menu MenuId="23">
    <Menu MenuId="42"/>
    <Menu MenuId="84">
      <Menu MenuId="198">
        <Menu MenuId="53"/>
      </Menu>
      <Menu MenuId="23"/>
    </Menu>
    <Menu MenuId="65"/>
  </Menu>
</Menus>

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.