![]() |
![]() | ![]() | ![]() | Altova Mailing List Archives>Archive Index >microsoft.public.xsl Archive Home >Recent entries >Thread Prev - Re: Displaying a table column by column >Thread Next - Re: Displaying a table column by column Re: Displaying a table column by columnTo: NULL Date: 2/14/2007 8:40:00 AM
On 14 f=E9v, 17:01, Martin Honnen <mahotr...@yahoo.de> wrote:
> cedric.lou...@gmail.com wrote:
> > I have an xml file looking like :
> > <col>
> > <line>11</line>
> > <line>21</line>
> > </col>
> > <col>
> > <line>12</line>
> > <line>22</line>
> > </col>
> > But I need to print out (printed column by column):
> > 11 12
> > 21 22
>
> Here is an example stylesheet:
>
> <xsl:stylesheet
> xmlns:xsl=3D"http://www.w3.org/1999/XSL/Transform"
> version=3D"1.0">
>
> <xsl:output method=3D"html" indent=3D"yes"/>
>
> <xsl:template match=3D"/">
> <html lang=3D"en">
> <head>
> <title>table example</title>
> </head>
> <body>
> <xsl:apply-templates/>
> </body>
> </html>
> </xsl:template>
>
> <xsl:template match=3D"/*">
> <table>
> <tbody>
> <xsl:apply-templates select=3D"col[1]/line" mode=3D"row"/>
> </tbody>
> </table>
> </xsl:template>
>
> <xsl:template match=3D"line" mode=3D"row">
> <xsl:variable name=3D"row-number" select=3D"position()"/>
> <tr>
> <xsl:apply-templates select=3D". |
> ../following-sibling::col/line[position() =3D $row-number]" mode=3D"cell"=
/>
> </tr>
> </xsl:template>
>
> <xsl:template match=3D"line" mode=3D"cell">
> <td><xsl:value-of select=3D"."/></td>
> </xsl:template>
>
> </xsl:stylesheet>
>
> --
>
> Martin Honnen --- MVP XML
> http://JavaScript.FAQTs.com/
Thanks a lot for your answer.
I've just found another solution which is a bit different from yours :
<table>
<tbody>
<xsl:for-each select=3D"col[1]/line">
<xsl:variable name=3D"numLine" select=3D"position()"/>
<tr>
<xsl:for-each select=3D"../../col">
<xsl:variable name=3D"numCol" select=3D"position()"/>
<td>
<xsl:value-of select=3D"."/>
</td>
</xsl:for-each>
</tr>
</xsl:for-each>
</tbody>
</table>
You use templates (whereas I don't) which makes your solution
clearer.
However you use the following-sibling axes and I don't use it (I use
another xsl:variable instead).
Can you help me figure out which of the 2 solutions (yours and mine)
is the best and why.
Thank you again.
| ![]() | ![]() | ![]() |
| Company | Legal | Press | Partners | Careers | Sitemap | Contact Us | Altova Blog | |||||
|
