henny Posted May 19, 2007 Share Posted May 19, 2007 hello,I've an agenda in xml and would like to create an xsl that formats the agenda in a html-tablestraight forward - no problembut now I would like to write a separation-line in the table, when the month changesso before I write the date-node, compare the month-node with the previous month-nodeif they are not equal => write a separation-lineI've tried with position()-1 but no successany clue ??thx in advance - Hennyhere is my sample hp.xml <?xml version="1.0" encoding="ISO-8859-1"?><agenda> <activity> <month>may 2006</month> <date>wednesday 31 may 2006</date> <desc>what you normally do on a wednesday in may</desc> </activity> <activity> <month>juni 2006</month> <date>monday 12 juni 2006</date> <desc>what you normally do on a monday in juni</desc> </activity> <activity> <month>juni 2006</month> <date>saturday 17 juni 2006</date> <desc>what you normally do on a saturday in juni</desc> </activity> <activity> <maand>september 2006</maand> <datum>saturday 9 september 2006</datum> <desc>what you normally do on a saturday in september</desc> </activity></agenda> here is my sample hp.xsl <?xml version="1.0" encoding="ISO-8859-1"?><xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"><xsl:template match="/"><html><body><table border="0" cellspacing="0" cellpadding="2" width="50%" align="center"> <tr> <td><h1>Date</h1></td> <td><h1>Description</h1></td> </tr> <xsl:for-each select="//agenda/activity"> <xsl:if test="position() = 1"> <tr><td><xsl:value-of select="month"/></td></tr> <tr><td width="10%" height="2" colspan="2" bgcolor="Navy"></td></tr> </xsl:if> <xsl:if test="position() > 1"> <tr><td><xsl:text>do the test to find out if the month has changed</xsl:text></td></tr> <tr><td width="10%" height="2" colspan="2" bgcolor="Navy"></td></tr> </xsl:if> <tr> <td><xsl:value-of select="date"/></td> <td><xsl:value-of select="desc"/></td> </tr> </xsl:for-each></table></body></html></xsl:template></xsl:stylesheet> and here is my sample hp.htm ( to transform the data into html ) <html><body><script language="javascript">// Load the XML var xml = new ActiveXObject("Microsoft.XMLDOM");xml.async = false;xml.load("hp.xml");// Load the XSLvar xsl = new ActiveXObject("Microsoft.XMLDOM");xsl.async = false;xsl.load("hp.xsl");// Transformdocument.write(xml.transformNode(xsl)); </script></body></html> Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.