Subject: RE: any ideas? From: Ben Robb <Ben@xxxxxxxxxx> Date: Thu, 4 Nov 1999 12:56:20 -0000 |
You could use a code like this (NB. Not tested, or even checked for well-formed XML/XSL *grin*): +++ XML +++ <SITE> <SECTION ID="1" LEVEL="1" TITLE="Section 1" LINK=""/> <SECTION ID="2" LEVEL="1" TITLE="Section 2" LINK=""> <SECTION ID="3" LEVEL="2" TITLE="Section 2.1" LINK=""/> <SECTION ID="4" LEVEL="2" TITLE="Section 2.2" LINK=""/> </SECTION> ... </SITE> +++ XSL +++ <xsl:for-each select="//SITE/SECTION"> <div onclick="JavaScript:displayChild()"> <xsl:attribute name="id">parent<xsl:value-of select="@ID"/></xsl:attribute> <img src="plus.gif"/><xsl:value-of select="@TITLE"/> </div> <div style="display:none"> <xsl:attribute name="id">child<xsl:value-of select="@ID"/></xsl:attribute> <xsl:for-each select="SECTION"> <xsl:value-of select="@TITLE"/><BR/> </xsl:for each> </div> </xsl:for-each> The JavaScript function "displayChild()" basically sets the style of display for the second div tag to be "" (ie. makes the child visible). I've left it to you to add things like positioning to get the div tags to appear in the right place. There are a couple of problems with this method 1) This will only work if there are two levels. Does anyone know of a way to do recursive for loops? Like "Carry on going down the tree doing the same sort of thing as long as there are more SECTION elements beneath it" without hard coding? I'm sure there is a way... 2) I toyed with the idea of making it a flat structure, which would mean that the order becomes very important, but gets rid of the problem in (1). ie: <SITE> <SECTION ID="1" LEVEL="1" TITLE="Section 1" LINK=""/> <SECTION ID="2" LEVEL="1" TITLE="Section 2" LINK=""/> <SECTION ID="3" LEVEL="2" TITLE="Section 2.1" LINK=""/> <SECTION ID="4" LEVEL="2" TITLE="Section 2.2" LINK=""/> ... </SITE> The problem with that, though, is that it is difficult to target the correct div tags to show and hide on the fly (since you don't know the "parent" of the item in the index. Anyone else have any thoughts? Ben Robb > -----Original Message----- > From: TaNiA [mailto:tania@xxxxxxxxxxxxxx] > Sent: 04 November 1999 04:00 > To: xsl > Subject: any ideas? > > > Hi all, > > was wondering if anyone could give me any pointers in > building a table of > contents like what Microsoft has using XML and XSL . > http://msdn.microsoft.com/workshop/xml/toc.htm > thanks in advance, > tania > > > > XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list > ********************************************************************** This email and any files transmitted with it are confidential and intended solely for the use of the individual or entity to whom they are addressed. If you have received this email in error please notify the system manager. This footnote also confirms that this email message has been swept by MIMEsweeper for the presence of computer viruses. ********************************************************************** XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
any ideas?, TaNiA | Thread | HTML Code!, Samir . Jasani |
RE: attributes and template modes, Kay Michael | Date | Stylesheet to view XML code in brow, Dylan Walsh |
Month |