XSL > HTML table building question

Discussion in 'XML' started by John Kooistra, Jun 30, 2004.

  1. Hi!

    I'm looking to generate an HTML table via XSL using XML data.

    Specifically, I want to arrange my data in a table with rows of 6
    columns. So, I have this conditional XSL statement setup to open and
    close <tr>'s when appropriate.

    Unfortunately, the XSL parser doesn't like the fact that within the
    <xsl:when> block there is no closing tag for <tr>. (ie. Receive the
    error message: "End tag 'xsl:when' does not match the start tag
    'tr'.")

    <code snippet>
    <xsl:for-each select="course">
    <xsl:choose>
    <xsl:when test="position() mod 6 = 1">
    <tr> <!-- PROBLEM -->
    <td>
    SOME DATA
    </td>
    </xsl:when>
    <xsl:when test="position() mod 6 = 0">
    <td>
    SOME DATA
    </td>
    </tr> <!-- PROBLEM -->
    </xsl:when>
    <xsl:eek:therwise>
    <td>
    SOME DATA
    </td>
    </xsl:eek:therwise>
    </xsl:choose>
    </xsl:for-each>
    </code snippet>

    Is there a way to tell the XSL parser that this is what I want and to
    leave me alone? Or is there another (better?) way of doing this?

    Thanks in advance,
    John

    P.S. I realize at this point that this code relies on a multiple of 6
    <course> blocks in the XML to create well-formed HTML.
    John Kooistra, Jun 30, 2004
    #1
    1. Advertising

  2. John Kooistra wrote:


    > Specifically, I want to arrange my data in a table with rows of 6
    > columns. So, I have this conditional XSL statement setup to open and
    > close <tr>'s when appropriate.
    >
    > Unfortunately, the XSL parser doesn't like the fact that within the
    > <xsl:when> block there is no closing tag for <tr>. (ie. Receive the
    > error message: "End tag 'xsl:when' does not match the start tag
    > 'tr'.")
    >
    > <code snippet>
    > <xsl:for-each select="course">
    > <xsl:choose>
    > <xsl:when test="position() mod 6 = 1">
    > <tr> <!-- PROBLEM -->
    > <td>
    > SOME DATA
    > </td>
    > </xsl:when>


    Well it is (most probably) not the XSLT processor complaining but
    already the XML parser used by the XSLT processor to parse your
    stylesheet which is not well-formed.
    You need to ensure your stylesheet is well-formed, if you want to
    conditionally output something in a template then you need to put a
    complete <tr> into one <xsl:when> branch.

    --

    Martin Honnen
    http://JavaScript.FAQTs.com/
    Martin Honnen, Jun 30, 2004
    #2
    1. Advertising

  3. On 30.06.2004 16:02, John Kooistra wrote:

    > Hi!
    >
    > I'm looking to generate an HTML table via XSL using XML data.
    >
    > Specifically, I want to arrange my data in a table with rows of 6
    > columns. So, I have this conditional XSL statement setup to open and
    > close <tr>'s when appropriate.
    >
    > Unfortunately, the XSL parser doesn't like the fact that within the
    > <xsl:when> block there is no closing tag for <tr>. (ie. Receive the
    > error message: "End tag 'xsl:when' does not match the start tag
    > 'tr'.")
    >
    > <code snippet>
    > <xsl:for-each select="course">
    > <xsl:choose>
    > <xsl:when test="position() mod 6 = 1">
    > <tr> <!-- PROBLEM -->
    > <td>
    > SOME DATA
    > </td>
    > </xsl:when>
    > <xsl:when test="position() mod 6 = 0">
    > <td>
    > SOME DATA
    > </td>
    > </tr> <!-- PROBLEM -->
    > </xsl:when>
    > <xsl:eek:therwise>
    > <td>
    > SOME DATA
    > </td>
    > </xsl:eek:therwise>
    > </xsl:choose>
    > </xsl:for-each>
    > </code snippet>
    >
    > Is there a way to tell the XSL parser that this is what I want and to
    > leave me alone? Or is there another (better?) way of doing this?
    >
    > Thanks in advance,
    > John
    >
    > P.S. I realize at this point that this code relies on a multiple of 6
    > <course> blocks in the XML to create well-formed HTML.



    Hm, perhaps something of this sort could help:


    <xsl:for-each select="course">
    <xsl:if test="position() mod 6 = 1">
    <tr>
    <xsl:variable name="pos" select="position()"/>
    <xsl:for-each select="../course[(position() &gt;= $pos)
    and (position() &lt; ($pos + 6))]">
    <td>
    SOME DATA
    </td>
    </xsl:for-each>
    </tr>
    </xsl:if>
    </xsl:for-each>


    It isn't pretty, but is should work.

    Ciao,
    Igor
    Igor Zlatkovic, Jun 30, 2004
    #3
  4. Igor from developersdex.com gave me this solution which worked well:

    -----------------------------
    Hm, perhaps something of this sort could help:


    <xsl:for-each select="course">
    <xsl:if test="position() mod 6 = 1">
    <tr>
    <xsl:variable name="pos" select="position()"/>
    <xsl:for-each select="../course[(position() >= $pos)
    and (position() < ($pos + 6))]">
    <td>
    SOME DATA
    </td>
    </xsl:for-each>
    </tr>
    </xsl:if>
    </xsl:for-each>


    It isn't pretty, but is should work.

    Ciao,
    Igor
    -----------------------------
    John Kooistra, Jun 30, 2004
    #4
  5. On 30.06.2004 22:12, John Kooistra wrote:

    > Igor from developersdex.com gave me this solution which worked well:


    What? developersdex.com? I posted to comp.text.xml, in the name of
    myself, to my own honour :) I never heard of developersdex.com, I am
    now interested in how I came to be connected to that lot?

    Ciao,
    Igor
    Igor Zlatkovic, Jun 30, 2004
    #5
  6. John Kooistra wrote:

    > Igor from developersdex.com gave me this solution which worked well:


    > <xsl:for-each select="course">
    > <xsl:if test="position() mod 6 = 1">
    > <tr>
    > <xsl:variable name="pos" select="position()"/>
    > <xsl:for-each select="../course[(position() >= $pos)
    > and (position() < ($pos + 6))]">
    > <td>
    > SOME DATA
    > </td>
    > </xsl:for-each>
    > </tr>
    > </xsl:if>
    > </xsl:for-each>


    That is well-formed and if the XSLT does what you want then use it.

    --

    Martin Honnen
    http://JavaScript.FAQTs.com/
    Martin Honnen, Jul 1, 2004
    #6
  7. John Kooistra

    Baldo Guest

    > <xsl:for-each select="course">
    > <xsl:if test="position() mod 6 = 1">
    > <tr>
    > <xsl:variable name="pos" select="position()"/>
    > <xsl:for-each select="../course[(position() &gt;= $pos)
    > and (position() &lt; ($pos + 6))]">
    > <td>
    > SOME DATA
    > </td>
    > </xsl:for-each>
    > </tr>
    > </xsl:if>
    > </xsl:for-each>


    another solution can be with:

    <xsl:text>&lt; tr &gt; </xls:text>


    --
    baldo
    Baldo, Jul 3, 2004
    #7
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Rio
    Replies:
    4
    Views:
    1,165
  2. Marrow
    Replies:
    0
    Views:
    4,121
    Marrow
    Jul 2, 2003
  3. Vijay singh
    Replies:
    1
    Views:
    425
    Martin Honnen
    Nov 4, 2004
  4. Replies:
    1
    Views:
    3,565
    A. Bolmarcich
    May 27, 2005
  5. Kourosh
    Replies:
    6
    Views:
    832
    Peter Flynn
    May 17, 2006
Loading...

Share This Page