Subject: RE: [xsl] XSL resources - Flat to hierarchy - Common ancestors From: "Ben Simkins" <bsimkins@xxxxxxxxxx> Date: Tue, 27 Jul 2004 17:20:41 +0200 |
*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 |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] XSL resources - Flat to h, M. David Peterson | Thread | Re: [xsl] XSL resources - Flat to h, David Carlisle |
Re: [xsl] can you select name() of , David Carlisle | Date | Re: [xsl] Any samples of client-sid, Emmanouil Batsis |
Month |