XSL > HTML table building question

J

John Kooistra

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.
 
M

Martin Honnen

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.
 
I

Igor Zlatkovic

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
 
J

John Kooistra

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
-----------------------------
 
I

Igor Zlatkovic

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
 
M

Martin Honnen

John said:
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.
 
B

Baldo

<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>
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,997
Messages
2,570,239
Members
46,827
Latest member
DMUK_Beginner

Latest Threads

Top