Subject: Re: XSL to popolate Popup Navigator Applet From: Jeni Tennison <jeni@xxxxxxxxxxxxxxxx> Date: Tue, 01 Aug 2000 22:23:36 +0100 |
Cristóbal, Mike Kay said: >> <param name="0" value="Version History;version_history.htm"> >> <param name="3;0" value="Defining Menu;defining_menu.htm"> > >I've no idea what you're trying to do, but parameter names must be valid XML >names, which means they can't start with a digit and they can't contain a >semicolon. because he didn't realise they were applet parameters, which can take any name (quite understandable when you're answering questions on XSLT parameters all the time). You haven't given an idea of the XSLT that you've managed to put together so far, or what the specific problem you're having is. I guess it's to do with constructing the name/value of the applet parameters that are dependent on the XML file. You want to generate a param element in your output for each folder element that you have in your input. So, you want a template that matches on a folder element and produces a param element based on its content, and then (as some folders can contain others) applies templates to those folders it contains: <xsl:template match="folder"> <param> ... </param> <xsl:apply-templates select="folder" /> </xsl:template> The things that alter about the 'param' element are its name and value attributes. I'll handle the value attribute first because it's easier. There are two types of 'folder' element: those that have an 'href' element as a child and those that have 'folder' children. In the first case, you want to give a 'value' attribute equal to the Text of the folder and its href, separated by a semicolon. In the second case, you want the value to just hold the Text of the folder. You can create an attribute using an xsl:attribute element within the param element in your template. You can use xsl:if to do the kind of conditional processing that you're after: <xsl:template match="folder"> <param> <xsl:attribute name="value"> <xsl:value-of select="Text" /> <xsl:if test="href"> <xsl:text>;</xsl:text> <xsl:value-of select="href" /> </xsl:if> </xsl:attribute> ... </param> <xsl:apply-templates select="folder" /> </xsl:template> Now we come to the naming of the param elements, which involves numbering the folders. I am certain that you should be able to do this with xsl:number, and indeed it *almost* gets you there with: <xsl:number level="multiple" format="1;1" /> which produces: <param name="1" value="Version History;version_history.htm"> <param name="2" value="Getting Started;getting_started.htm"> <param name="3" value="About Sub-Parameters;subparameters.htm"> <param name="4" value="Menu"> <param name="4;1" value="Defining Menu;defining_menu.htm"> <param name="4;2" value="MenuActivation;parameter_menuactivation.htm "> <param name="4;3" value="MenuPosition;parameter_menuposition.htm "> ... but you want your param numbering to start at 0, and I simply cannot find a way to do that, especially as my copy of Mike's book is lost somewhere right now. For now, until someone posts a neat solution, you can generate the number by iterating over the ancestor (or self) folders and numbering them by counting the number of preceding siblings they have. The ';' separator is added for all but the last in the list: <xsl:template match="folder"> <param> <xsl:attribute name="value"> <xsl:value-of select="Text" /> <xsl:if test="href"> <xsl:text>;</xsl:text> <xsl:value-of select="href" /> </xsl:if> </xsl:attribute> <xsl:attribute name="name"> <xsl:for-each select="ancestor-or-self::folder"> <xsl:value-of select="count(preceding-sibling::folder)" /> <xsl:if test="position() != last()">;</xsl:if> </xsl:for-each> </xsl:attribute> </param> <xsl:apply-templates select="folder" /> </xsl:template> With the relevant calling template, i.e.: <xsl:template match="navigate"> <applet code="PopupNavigator/PopupNavigatorApplet.class" archive="/WWWComun/CGIs/Java/Applets/Terceros/PopupNavigator-111/documentati on/PopupNavigator.jar" width="128" height="24"> <param name="Label" value="Navegar;Courier;BOLDITALIC;16;BLACK;200 255 0" /> <param name="MenuPosition" value="BOTTOM" /> <param name="MouseoverLabel" value=";;;;RED;210 210 210" /> <param name="MissingUrl" value="DISABLE" /> <xsl:apply-templates select="folder" /> PopupNavigator Java Applet - JDK 1.1.3 needed PopupNavigator Java Applet - JDK 1.1.3 needed </applet> </xsl:template> and the correction of the typos in your XML document, this produces the output you want in SAXON. I hope that helps, Jeni Dr Jeni Tennison Epistemics Ltd * Strelley Hall * Nottingham * NG8 6PE tel: 0115 906 1301 * fax: 0115 906 1304 * email: jeni.tennison@xxxxxxxxxxxxxxxx XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: Can I add new element?, Jeni Tennison | Thread | RE: include vs. xsl:import, Matthew Bentley |
RE: jdom, Kaganovich, Yevgeniy | Date | RE: FO, Matthew Bentley |
Month |