Subject: RE: [xsl] Carlos Problem (II) how to show some results y some pla ces: From: TSchutzerWeissmann@xxxxxxxxxxxxxxxx Date: Fri, 10 May 2002 10:43:48 +0100 |
Carlos wrote: >is a very good method but i need other thing; in the fist td 1 4 7 elements, >in the second 2 5 8 in the tree elemnt 3 6 9 >can anybody help me please, i must to solve this problem in my hob, i am >exasperated, i am working in this problem one week and i cannot solve. >please help me > > >i want to present in this form: ><table> ><tr> ><td>1 4 7....</td><td>2 5 8....</td><td>3 6 9....</td> ></tr> ></table> >and i dont want: ><table> ><tr> ><td>1</td><td>2</td><td>3</td> ></tr> ><tr> ><td>4</td><td>5</td><td>6</td> ></tr> ><tr> ><td>7</td><td>8</td><td>9</td> ></tr> ></table> Hello Carlos, Let say you want 3 columns. That means: in column 1 you want element 1 (1 mod 3 = 1) , 4 (4 mod 3 = 1), 7 (7 mod 3 = 1) In column 2: 2, 5, 8 (5 mod 3 = 2) etc. In fact, it looks as if with x columns, for column c you want elements where position() mod x = c. BUT in column 3: 3 mod 3 = 0: this is the exception. The stylesheet below uses a for-each to get the first 3 elements and uses them to generate a variable called $mod, which counts from 1 to the number of columns desired (in this case, 3), but ensures that the last value is a 0. So it counts 1 to 3 like this: 1, 2, 0. The second for-each goes through all the REGISTRO elements, and groups them according to the scheme explained above. It should be fairly easy to adapt this method as a mode in your existing stylesheet. Good luck, Tom Weissmann <?xml version='1.0' encoding='UTF-8' standalone='yes'?> <xsl:stylesheet version='1.0' xmlns:xsl='http://www.w3.org/1999/XSL/Transform'> <xsl:template match='/'> <html> <body> <xsl:apply-templates select='/INMOBILIARIAS'> <xsl:with-param name ="colCount" select ="3"/> </xsl:apply-templates> </body> </html> </xsl:template> <xsl:template match="INMOBILIARIAS"> <xsl:param name="colCount" select="/.."/> <!-- the number of columns to span --> <table> <tr> <!-- it looks like you only want just one row - maybe --> <xsl:for-each select="REGISTRO[position() <= $colCount]"> <!-- the first for-each - count 1 to $colCount --> <xsl:variable name='mod'> <xsl:choose> <!-- for the $colCount-th set, $mod needs to be 0, not $colCount --> <xsl:when test='position() mod $colCount = 0'> 0 </xsl:when> <xsl:otherwise> <xsl:value-of select='position()'/> </xsl:otherwise> </xsl:choose> </xsl:variable> <td> <xsl:for-each select="../REGISTRO[position() mod $colCount = $mod]"> <xsl:sort select='position()'/> <xsl:value-of select="./REFERENCIA"/> </xsl:for-each> </td> </xsl:for-each> </tr> </table> </xsl:template> </xsl:stylesheet> XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] Using a second xml docume, John Sands | Thread | [xsl] linking transformations, Joeri Belis |
Re: [xsl] Carlos Problem (II) how t, Carlos | Date | Re: [xsl] CDATA block to node set., Morten Primdahl |
Month |