Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


Re: Displaying a table column by column

From: cedric.louyot@-----.---
To: 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.



transparent
Print
Mail
Digg
delicious
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent