Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


Re: Different table columns for odd and even elements

From: "Anthony Jones" <Ant@------------.--->
To: NULL
Date: 6/1/2006 10:11:00 AM


"ScottL" <slanders770@m...> wrote in message
news:uzIonoBhGHA.3652@T......
> I have a XML doc similar to the following:
>
> <Person ID="A" Name="Steve">
> <Person ID="B" Name="Jane">
> <Person ID="C" Name="Joe">
> <Person ID="D" Name="Bob">
> <Person ID="E" Name="Dan">
> <Person ID="F" Name="Harry">
>
> I want to represent it in a table as follows:
> Person     Name        Person     Name
> A             Steve          B            Jane
> C             Joe             D            Bob
> E             Dan            F            Harry
>
> The XSL below is incomplete but it will give you an idea of (how bad I am
at
> XSL) how far I have gotten.
>
> <xsl:variable name="Persons" select="/Person"/>
> <table border="1">
>
>    <xsl:for-each select="$Persons">
>    <xsl:if test="position() mod 2 = 1">
>    <xsl:for-each select="@*">
>    <tr>
>      <td>
>          <xsl:value-of select="name()"/>
>                </td>
>                <td>
>                        <xsl:value-of select="."/>
>                     </td>
>    </tr>
>
>      </xsl:for-each>
>    </xsl:if>
>
>
>    <xsl:if test="position() mod 2 = 0">
>    <xsl:for-each select="@*">
>      <td>
>                  <xsl:value-of select="name()"/>
>                </td>
>                <td>
>                        <xsl:value-of select="."/>
>                     </td>
>    </xsl:for-each>
>    </xsl:if>
>
>      </xsl:for-each>
>
> </table>
>
> Can anyone help me with this. I am currenlty use the position() mod 2 = 0
> and position() mod 2 = 1 expressions to get odd and even elements but I
> cannot get them to dispay in the appropriate columns.
> Any ideas would be greatly appreciated.
>
> Thanks!
>
> Scott Landers
>

<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
 <xsl:output method="html" encoding="UTF-8" />
 <xsl:param name="cellCount" select="2" />
 <xsl:template match="Persons">
  <table rules="all">
   <thead>
    <tr>
     <xsl:call-template name="headers">
      <xsl:with-param name="depth" select="$cellCount" />
     </xsl:call-template>
    </tr>
   </thead>
   <xsl:for-each select="Person[position() mod $cellCount = 1]">
    <tr>
     <xsl:for-each select=". | following-sibling::Person[position() &lt;
$cellCount]">
      <td><xsl:value-of select="@ID" /></td>
      <td><xsl:value-of select="@Name" /></td>
     </xsl:for-each>
    </tr>
   </xsl:for-each>
  </table>
 </xsl:template>

 <xsl:template name="headers">
  <xsl:param name="depth" />
  <xsl:if test="$depth &gt; 0">
   <th>ID</th><th>Name</th>
   <xsl:call-template name="headers">
    <xsl:with-param name="depth" select="$depth - 1" />
   </xsl:call-template>
  </xsl:if>
 </xsl:template>

</xsl:stylesheet>


You can control the number or records presented per row by changing the
cellCount parameter.  If using an XSL Processor you can do this
programmatically.





transparent
Print
Mail
Like It
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