Subject: [xsl] How to form correct structure From: "David O Baldwin" <david.baldwin@xxxxxxxxxxxx> Date: Mon, 10 Sep 2001 16:35:59 +0100 |
I have a question about how to form the correct structure of nodes in my result set. I have an xml file which represents a set of Menu items. I am attempting to transform each Menu node into an HTML DIV. My problem is that for each branch of the menu I need to contain the rest of the entire menu in a further DIV. A simplified version of the XML is as follows: (The Description of each Menu reflects its level in the node set) <?xml version="1.0"?> <Menu> <Menu Description="menuOne"> <Menu Description="menuOneOne"> </Menu> <Menu Description="menuOneTwo"> <Menu Description="menuOneTwoOne"> </Menu> </Menu> <Menu Description="menuOneThree"> </Menu> </Menu> <Menu Description="menuTwo"> <Menu Description="menuTwoOne"> </Menu> </Menu> </Menu> A simplified version of the XSL is as follows: <xsl:template match="/"> <xsl:apply-templates select="Menu"/> </xsl:template> <xsl:template match="Menu"> <xsl:variable name="MenuID">menu<xsl:number level="multiple" count="Menu" format="1_1"/></xsl:variable> <DIV> <xsl:attribute name="ID"> <xsl:value-of select="$MenuID"/> </xsl:attribute> <xsl:value-of select="@Description"/> </DIV> <xsl:if test="Menu"> <xsl:apply-templates select="Menu"/> <DIV> <xsl:attribute name="ID">Block_<xsl:value-of select="$MenuID"/></xsl:attribute> </DIV> </xsl:if> </xsl:template> The resulting output is as follows <DIV ID="menu"></DIV> <DIV ID="menu_1">menuOne</DIV> <DIV ID="menu_1_1">menuOneOne</DIV> <DIV ID="menu_1_2">menuOneTwo</DIV> <DIV ID="menu_1_2_1">menuOneTwoOne</DIV> <DIV ID="Block_menu_1_2"> </DIV> <DIV ID="menu_1_3">menuOneThree</DIV> <DIV ID="Block_menu_1"> </DIV> <DIV ID="menu_2">menuTwo</DIV> <DIV ID="menu_2_1">menuTwoOne</DIV> <DIV ID="Block_menu_2"> </DIV> <DIV ID="Block_menu"> </DIV> However, the desired output is to have the 'Block' DIVs surrounding the rest of the menu as follows, with the order of the menu DIVs remaining the same: <DIV ID="menu"></DIV> <DIV ID="menu_1">menuOne</DIV> <DIV ID="menu_1_1">menuOneOne</DIV> <DIV ID="menu_1_2">menuOneTwo</DIV> <DIV ID="menu_1_2_1">menuOneTwoOne</DIV> <DIV ID="Block_menu_1_2"> <DIV ID="menu_1_3">menuOneThree</DIV> <DIV ID="Block_menu_1"> <DIV ID="menu_2">menuTwo</DIV> <DIV ID="menu_2_1">menuTwoOne</DIV> <DIV ID="Block_menu_2"> <DIV ID="Block_menu"> </DIV> </DIV> </DIV> </DIV> I think that what I need to do is to change the XSL to be something like <xsl:if test="Menu"> <xsl:apply-templates select={expression to select only direct descendents of current node} /> <DIV> <xsl:attribute name="ID">Block_<xsl:value-of select="$MenuID"/></xsl:attribute> <xsl:apply-templates select={expression to select only following siblings of current node} /> </DIV> </xsl:if> but I have not managed to get anywhere near what I am after, so maybe I am barking up the wrong tree. It seems as though what I am trying to do is create a nested structure based on the structure of the original XML, but using different nodes. Does anyone have any ideas as to how to approach this problem? I can probably write something in ASP to convert the XML for me, but I would rather find out how it could be done in XSL. Thanks for any pointers/ideas. David Baldwin XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
RE: [xsl] Selecting nodes whose tex, Michael Kay | Thread | RE: [xsl] How to form correct struc, Chris Bayes |
Re: [xsl] pass value between xml an, Jennifer Hochgesang | Date | [xsl] I don't unterstand!, Auguste Oumar |
Month |