Subject: [xsl] XSL menu using multiple row HTML table From: Lea Allison <Lea.Allison@xxxxxxxxxxxxxx> Date: Wed, 27 Feb 2002 16:26:59 +0100 |
Hello I've have a problem that has had me up for 2 days, and I've learnt alot, but now my head is just busting... I need help! I am trying to create a template that will convert my XML menu doc (extract below) into an HTML menu. The menu I wont is the horizontal type, and the real problem I have is selecting the number of menu items per row. I cannot figure out how to get the stylesheet to read the first X number of items in, then start a new row, and another until complete. I cannot use "for-each" to split the <TR> and </TR> tags without creating bad XML... and using named templates recursively loses me when one row is complete and I want to continue my proccessing on the newxt row. OK, here is a snippet of the source XML: <LIBRARY> <WEB> <HOME isCategory="yes"> <NAME>Home</NAME> <DESCRIPTION>Virgin Home page</DESCRIPTION> </HOME> <VIRGININFO isCategory="yes" icon="" hide="no"> <NAME>Virgin Info</NAME> <DESCRIPTION>Virgin commercial information</DESCRIPTION> <CORPORATE isCategory="yes" icon="" hide="no"> <NAME>Corporate</NAME> <DESCRIPTION>Corporate information</DESCRIPTION> </CORPORATE> </VIRGININFO> ... ... <TEST> <NAME>LEA</NAME> </TEST> </WEB> </LIBRARY> I don't think this is the best way for trying to do this job, but the reason is that I'm using XPath from my app to access these items... I'll get round that, but here's my problem. This what I've got after 2 days deleting and re-writing so please ignore this if it is completly wrong: <?xml version="1.0"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output method="html"/> <xsl:template match="/"> <HTML><BODY> <TABLE border="1" width="100%"> <xsl:apply-templates select="LIBRARY/WEB" /> </TABLE> </BODY> </HTML> </xsl:template> <xsl:template match="LIBRARY/WEB"> <xsl:param name="max">8</xsl:param> <!-- MAX ITEMS PER TABLE ROW --> <TR> <xsl:for-each select="*"> <xsl:choose> <xsl:when test="position() -1 < $max"> <xsl:apply-templates select="NAME" /> </xsl:when> </xsl:choose> </xsl:for-each> </TR> <!-- xsl:apply-templates select="//LIBRARY/WEB" / --> <!-- !!!! err ? --> </xsl:template> <xsl:template match="NAME"> <TD><B><xsl:apply-templates /></B></TD> </xsl:template> <xsl:template match="*" /> </xsl:stylesheet> Cheers!! Lea XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
[xsl] Re: Value-of, copy-of, Dimitre Novatchev | Thread | Re: [xsl] XSL menu using multiple r, Joerg Heinicke |
[xsl] Re: Value-of, copy-of, Dimitre Novatchev | Date | Re: [xsl] String comparisons fail u, Thomas B. Passin |
Month |